Skip to content

Commit a93d33e

Browse files
Pete Wyckoffgitster
authored andcommitted
git-p4: set useClientSpec variable on initial clone
If --use-client-spec was given, set the matching configuration variable. This is necessary to ensure that future submits work properly. The alternatives of requiring the user to set it, or providing a command-line option on every submit, are error prone. Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 07f050c commit a93d33e

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Documentation/git-p4.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,13 @@ CLIENT SPEC
303303
-----------
304304
The p4 client specification is maintained with the 'p4 client' command
305305
and contains among other fields, a View that specifies how the depot
306-
is mapped into the client repository. Git-p4 can consult the client
307-
spec when given the '--use-client-spec' option or useClientSpec
308-
variable.
306+
is mapped into the client repository. The 'clone' and 'sync' commands
307+
can consult the client spec when given the '--use-client-spec' option or
308+
when the useClientSpec variable is true. After 'git p4 clone', the
309+
useClientSpec variable is automatically set in the repository
310+
configuration file. This allows future 'git p4 submit' commands to
311+
work properly; the submit command looks only at the variable and does
312+
not have a command-line option.
309313

310314
The full syntax for a p4 view is documented in 'p4 help views'. Git-p4
311315
knows only a subset of the view syntax. It understands multi-line

contrib/fast-import/git-p4

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ class P4Sync(Command, P4UserMap):
14281428
self.p4BranchesInGit = []
14291429
self.cloneExclude = []
14301430
self.useClientSpec = False
1431+
self.useClientSpec_from_options = False
14311432
self.clientSpecDirs = None
14321433

14331434
if gitConfig("git-p4.syncFromOrigin") == "false":
@@ -2136,7 +2137,11 @@ class P4Sync(Command, P4UserMap):
21362137
if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch):
21372138
system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
21382139

2139-
if not self.useClientSpec:
2140+
# accept either the command-line option, or the configuration variable
2141+
if self.useClientSpec:
2142+
# will use this after clone to set the variable
2143+
self.useClientSpec_from_options = True
2144+
else:
21402145
if gitConfig("git-p4.useclientspec", "--bool") == "true":
21412146
self.useClientSpec = True
21422147
if self.useClientSpec:
@@ -2455,6 +2460,10 @@ class P4Clone(P4Sync):
24552460
else:
24562461
print "Could not detect main branch. No checkout/master branch created."
24572462

2463+
# auto-set this variable if invoked with --use-client-spec
2464+
if self.useClientSpec_from_options:
2465+
system("git config --bool git-p4.useclientspec true")
2466+
24582467
return True
24592468

24602469
class P4Branches(Command):

t/t9809-git-p4-client-view.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ test_expect_success 'quotes on rhs only' '
240240
git_verify "cdir 1/file11" "cdir 1/file12"
241241
'
242242

243+
#
244+
# Submit tests
245+
#
246+
247+
# clone sets variable
248+
test_expect_success 'clone --use-client-spec sets useClientSpec' '
249+
client_view "//depot/... //client/..." &&
250+
test_when_finished cleanup_git &&
251+
"$GITP4" clone --use-client-spec --dest="$git" //depot &&
252+
(
253+
cd "$git" &&
254+
git config --bool git-p4.useClientSpec >actual &&
255+
echo true >true &&
256+
test_cmp actual true
257+
)
258+
'
259+
243260
#
244261
# Rename directories to test quoting in depot-side mappings
245262
# //depot

0 commit comments

Comments
 (0)