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 <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Feb 25, 2012 at 20:06 UTC
a93d33ee7bf2f1cd41f94470e9e44e0fc9307046
3 files changed
+34
-4
Documentation/git-p4.txt
+7
-3
@@ -303,9 +303,13 @@ CLIENT SPEC
303
-----------
304
The p4 client specification is maintained with the 'p4 client' command
305
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.
313
314
The full syntax for a p4 view is documented in 'p4 help views'. Git-p4
315
knows only a subset of the view syntax. It understands multi-line
contrib/fast-import/git-p4
+10
-1
@@ -1428,6 +1428,7 @@ class P4Sync(Command, P4UserMap):
1428
self.p4BranchesInGit = []
1429
self.cloneExclude = []
1430
self.useClientSpec = False
1431
+ self.useClientSpec_from_options = False
1432
self.clientSpecDirs = None
1433
1434
if gitConfig("git-p4.syncFromOrigin") == "false":
@@ -2136,7 +2137,11 @@ class P4Sync(Command, P4UserMap):
2137
if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch):
2138
system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
2139
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:
2145
if gitConfig("git-p4.useclientspec", "--bool") == "true":
2146
self.useClientSpec = True
2147
if self.useClientSpec:
@@ -2455,6 +2460,10 @@ class P4Clone(P4Sync):
2460
else:
2461
print "Could not detect main branch. No checkout/master branch created."
2462
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
+
2467
return True
2468
2469
class P4Branches(Command):
t/t9809-git-p4-client-view.sh
+17
@@ -240,6 +240,23 @@ test_expect_success 'quotes on rhs only' '
240
git_verify "cdir 1/file11" "cdir 1/file12"
241
'
242
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
+
260
#
261
# Rename directories to test quoting in depot-side mappings
262
# //depot