Skip to content

Commit 44e8d26

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: fix submit when no master branch
It finds its upstream and applies the commit properly, but the sync step will fail unless it is told which branch to work on. Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af8c009 commit 44e8d26

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Documentation/git-p4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ These options can be used to modify 'git p4 submit' behavior.
294294
to bypass the prompt, causing conflicting commits to be automatically
295295
skipped, or to quit trying to apply commits, without prompting.
296296

297+
--branch <branch>::
298+
After submitting, sync this named branch instead of the default
299+
p4/master. See the "Sync options" section above for more
300+
information.
301+
297302
Rebase options
298303
~~~~~~~~~~~~~~
299304
These options can be used to modify 'git p4 rebase' behavior.

git-p4.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ def __init__(self):
921921
optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
922922
optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
923923
optparse.make_option("--conflict", dest="conflict_behavior",
924-
choices=self.conflict_behavior_choices)
924+
choices=self.conflict_behavior_choices),
925+
optparse.make_option("--branch", dest="branch"),
925926
]
926927
self.description = "Submit changes from git to the perforce depot."
927928
self.usage += " [name of git branch to submit into perforce depot]"
@@ -934,6 +935,7 @@ def __init__(self):
934935
self.isWindows = (platform.system() == "Windows")
935936
self.exportLabels = False
936937
self.p4HasMoveCommand = p4_has_move_command()
938+
self.branch = None
937939

938940
def check(self):
939941
if len(p4CmdList("opened ...")) > 0:
@@ -1670,6 +1672,8 @@ def run(self, args):
16701672
print "All commits applied!"
16711673

16721674
sync = P4Sync()
1675+
if self.branch:
1676+
sync.branch = self.branch
16731677
sync.run([])
16741678

16751679
rebase = P4Rebase()

t/t9806-git-p4-options.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,31 @@ test_expect_success 'clone --use-client-spec' '
251251
)
252252
'
253253

254+
test_expect_success 'submit works with no p4/master' '
255+
test_when_finished cleanup_git &&
256+
git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
257+
(
258+
cd "$git" &&
259+
test_commit submit-1-branch &&
260+
git config git-p4.skipSubmitEdit true &&
261+
git p4 submit --branch=b1
262+
)
263+
'
264+
265+
# The sync/rebase part post-submit will engage detect-branches
266+
# machinery which will not do anything in this particular test.
267+
test_expect_success 'submit works with two branches' '
268+
test_when_finished cleanup_git &&
269+
git p4 clone --branch=b1 //depot@1,2 --destination="$git" &&
270+
(
271+
cd "$git" &&
272+
git p4 sync --branch=b2 //depot@1,3 &&
273+
test_commit submit-2-branches &&
274+
git config git-p4.skipSubmitEdit true &&
275+
git p4 submit
276+
)
277+
'
278+
254279
test_expect_success 'kill p4d' '
255280
kill_p4d
256281
'

0 commit comments

Comments
 (0)