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 <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jan 14, 2013 at 19:47 UTC 44e8d26cf3fbc0795fb1c44f54f458847313d35e
3 files changed +35 -1
Documentation/git-p4.txt
+5
@@ -294,6 +294,11 @@ These options can be used to modify 'git p4 submit' behavior.
294 to bypass the prompt, causing conflicting commits to be automatically
295 skipped, or to quit trying to apply commits, without prompting.
296
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 +
302 Rebase options
303 ~~~~~~~~~~~~~~
304 These options can be used to modify 'git p4 rebase' behavior.
git-p4.py
+5 -1
@@ -921,7 +921,8 @@ class P4Submit(Command, P4UserMap):
921 optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
922 optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
923 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"),
926 ]
927 self.description = "Submit changes from git to the perforce depot."
928 self.usage += " [name of git branch to submit into perforce depot]"
@@ -934,6 +935,7 @@ class P4Submit(Command, P4UserMap):
935 self.isWindows = (platform.system() == "Windows")
936 self.exportLabels = False
937 self.p4HasMoveCommand = p4_has_move_command()
938 + self.branch = None
939
940 def check(self):
941 if len(p4CmdList("opened ...")) > 0:
@@ -1670,6 +1672,8 @@ class P4Submit(Command, P4UserMap):
1672 print "All commits applied!"
1673
1674 sync = P4Sync()
1675 + if self.branch:
1676 + sync.branch = self.branch
1677 sync.run([])
1678
1679 rebase = P4Rebase()
t/t9806-git-p4-options.sh
+25
@@ -251,6 +251,31 @@ test_expect_success 'clone --use-client-spec' '
251 )
252 '
253
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 +
279 test_expect_success 'kill p4d' '
280 kill_p4d
281 '