Skip to content

Commit 28755db

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09fca77 commit 28755db

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

Documentation/git-p4.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ These options can be used to modify 'git p4 submit' behavior.
267267

268268
-M[<n>]::
269269
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.
271273

272274
--preserve-user::
273275
Re-author p4 changes before submitting to p4. This option
@@ -453,7 +455,9 @@ git-p4.skipSubmitEditCheck::
453455
git-p4.allowSubmit::
454456
By default, any branch can be used as the source for a 'git p4
455457
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.
457461

458462
git-p4.skipUserNameCheck::
459463
If the user running 'git p4 submit' does not exist in the p4

contrib/fast-import/git-p4

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ def isValidGitDir(path):
362362
def parseRevision(ref):
363363
return read_pipe("git rev-parse %s" % ref).strip()
364364

365+
def branchExists(ref):
366+
rev = read_pipe(["git", "rev-parse", "-q", "--verify", ref],
367+
ignore_error=True)
368+
return len(rev) > 0
369+
365370
def extractLogMessageFromGitCommit(commit):
366371
logMessage = ""
367372

@@ -1089,6 +1094,8 @@ class P4Submit(Command, P4UserMap):
10891094
die("Detecting current git branch failed!")
10901095
elif len(args) == 1:
10911096
self.master = args[0]
1097+
if not branchExists(self.master):
1098+
die("Branch %s does not exist" % self.master)
10921099
else:
10931100
return False
10941101

t/t9807-git-p4-submit.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,60 @@ test_expect_success 'submit with no client dir' '
3131
)
3232
'
3333

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+
3488
test_expect_success 'kill p4d' '
3589
kill_p4d
3690
'

0 commit comments

Comments
 (0)