git-p4: document and test submit options
Clarify there is a -M option, but no -C. These are both configurable through variables. Explain that the allowSubmit variable takes a comma-separated list of branch names. Catch earlier an invalid branch name given as an argument to "git p4 clone". Test option --origin, variable allowSubmit, and explicit master branch name. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Dec 24, 2011 at 21:07 UTC
28755dbaa5213032b2da202652c214a9f94ff853
3 files changed
+67
-2
Documentation/git-p4.txt
+6
-2
@@ -267,7 +267,9 @@ These options can be used to modify 'git p4 submit' behavior.
267
268
-M[<n>]::
269
Detect renames. See linkgit:git-diff[1]. Renames will be
270
- represented in p4 using explicit 'move' operations.
270
+ represented in p4 using explicit 'move' operations. There
271
+ is no corresponding option to detect copies, but there are
272
+ variables for both moves and copies.
273
274
--preserve-user::
275
Re-author p4 changes before submitting to p4. This option
@@ -453,7 +455,9 @@ git-p4.skipSubmitEditCheck::
455
git-p4.allowSubmit::
456
By default, any branch can be used as the source for a 'git p4
457
submit' operation. This configuration variable, if set, permits only
456
- the named branches to be used as submit sources.
458
+ the named branches to be used as submit sources. Branch names
459
+ must be the short names (no "refs/heads/"), and should be
460
+ separated by commas (","), with no spaces.
461
462
git-p4.skipUserNameCheck::
463
If the user running 'git p4 submit' does not exist in the p4
contrib/fast-import/git-p4
+7
@@ -362,6 +362,11 @@ def isValidGitDir(path):
362
def parseRevision(ref):
363
return read_pipe("git rev-parse %s" % ref).strip()
364
365
+def branchExists(ref):
366
+ rev = read_pipe(["git", "rev-parse", "-q", "--verify", ref],
367
+ ignore_error=True)
368
+ return len(rev) > 0
369
+
370
def extractLogMessageFromGitCommit(commit):
371
logMessage = ""
372
@@ -1089,6 +1094,8 @@ class P4Submit(Command, P4UserMap):
1094
die("Detecting current git branch failed!")
1095
elif len(args) == 1:
1096
self.master = args[0]
1097
+ if not branchExists(self.master):
1098
+ die("Branch %s does not exist" % self.master)
1099
else:
1100
return False
1101
t/t9807-git-p4-submit.sh
+54
@@ -31,6 +31,60 @@ test_expect_success 'submit with no client dir' '
31
)
32
'
33
34
+# make two commits, but tell it to apply only from HEAD^
35
+test_expect_success 'submit --origin' '
36
+ test_when_finished cleanup_git &&
37
+ "$GITP4" clone --dest="$git" //depot &&
38
+ (
39
+ cd "$git" &&
40
+ test_commit "file3" &&
41
+ test_commit "file4" &&
42
+ git config git-p4.skipSubmitEdit true &&
43
+ "$GITP4" submit --origin=HEAD^
44
+ ) &&
45
+ (
46
+ cd "$cli" &&
47
+ p4 sync &&
48
+ test_path_is_missing "file3.t" &&
49
+ test_path_is_file "file4.t"
50
+ )
51
+'
52
+
53
+test_expect_success 'submit with allowSubmit' '
54
+ test_when_finished cleanup_git &&
55
+ "$GITP4" clone --dest="$git" //depot &&
56
+ (
57
+ cd "$git" &&
58
+ test_commit "file5" &&
59
+ git config git-p4.skipSubmitEdit true &&
60
+ git config git-p4.allowSubmit "nobranch" &&
61
+ test_must_fail "$GITP4" submit &&
62
+ git config git-p4.allowSubmit "nobranch,master" &&
63
+ "$GITP4" submit
64
+ )
65
+'
66
+
67
+test_expect_success 'submit with master branch name from argv' '
68
+ test_when_finished cleanup_git &&
69
+ "$GITP4" clone --dest="$git" //depot &&
70
+ (
71
+ cd "$git" &&
72
+ test_commit "file6" &&
73
+ git config git-p4.skipSubmitEdit true &&
74
+ test_must_fail "$GITP4" submit nobranch &&
75
+ git branch otherbranch &&
76
+ git reset --hard HEAD^ &&
77
+ test_commit "file7" &&
78
+ "$GITP4" submit otherbranch
79
+ ) &&
80
+ (
81
+ cd "$cli" &&
82
+ p4 sync &&
83
+ test_path_is_file "file6.t" &&
84
+ test_path_is_missing "file7.t"
85
+ )
86
+'
87
+
88
test_expect_success 'kill p4d' '
89
kill_p4d
90
'