Skip to content

Commit

Permalink
git p4: move conflict prompt into run, add [q]uit input
Browse files Browse the repository at this point in the history
When applying a commit to the p4 workspace fails, a prompt
asks what to do next.  This belongs up in run() instead
of in applyCommit(), where run() can notice, for instance,
that the prompt is unnecessary because this is the last commit.

Offer two options about how to continue at conflict: [s]kip or
[q]uit.  Having an explicit "quit" option gives git p4 a chance
to clean up, show the applied-commit summary, and do tag export.

Signed-off-by: Pete Wyckoff <pw@padd.com>
Acked-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Pete Wyckoff authored and Junio C Hamano committed Sep 17, 2012
1 parent 449bb9c commit 7e5dd9f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
41 changes: 29 additions & 12 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,17 +1198,11 @@ def applyCommit(self, id):
patch_succeeded = True

if not patch_succeeded:
print "What do you want to do?"
response = "x"
while response != "s":
response = raw_input("[s]kip this patch ")
if response == "s":
print "Skipping! Good luck with the next patches..."
for f in editedFiles:
p4_revert(f)
for f in filesToAdd:
os.remove(f)
return False
for f in editedFiles:
p4_revert(f)
for f in filesToAdd:
os.remove(f)
return False

system(applyPatchCmd)

Expand Down Expand Up @@ -1475,11 +1469,34 @@ def run(self, args):
if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
self.diffOpts += " --find-copies-harder"

#
# Apply the commits, one at a time. On failure, ask if should
# continue to try the rest of the patches, or quit.
#
applied = []
for commit in commits:
last = len(commits) - 1
for i, commit in enumerate(commits):
ok = self.applyCommit(commit)
if ok:
applied.append(commit)
else:
if i < last:
quit = False
while True:
print "What do you want to do?"
response = raw_input("[s]kip this commit but apply"
" the rest, or [q]uit? ")
if not response:
continue
if response[0] == "s":
print "Skipping this commit, but applying the rest"
break
if response[0] == "q":
print "Quitting"
quit = True
break
if quit:
break

chdir(self.oldWorkingDirectory)

Expand Down
31 changes: 27 additions & 4 deletions t/t9815-git-p4-submit-fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test_expect_success 'init depot' '
)
'

test_expect_success 'conflict on one commit, skip' '
test_expect_success 'conflict on one commit' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
Expand All @@ -34,12 +34,12 @@ test_expect_success 'conflict on one commit, skip' '
echo line3 >>file1 &&
git add file1 &&
git commit -m "line3 in file1 will conflict" &&
echo s | test_expect_code 1 git p4 submit >out &&
test_expect_code 1 git p4 submit >out &&
test_i18ngrep "No commits applied" out
)
'

test_expect_success 'conflict on second of two commits, skip' '
test_expect_success 'conflict on second of two commits' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
Expand All @@ -57,7 +57,7 @@ test_expect_success 'conflict on second of two commits, skip' '
echo line4 >>file1 &&
git add file1 &&
git commit -m "line4 in file1 will conflict" &&
echo s | test_expect_code 1 git p4 submit >out &&
test_expect_code 1 git p4 submit >out &&
test_i18ngrep "Applied only the commits" out
)
'
Expand Down Expand Up @@ -85,6 +85,29 @@ test_expect_success 'conflict on first of two commits, skip' '
)
'

test_expect_success 'conflict on first of two commits, quit' '
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$cli" &&
p4 open file1 &&
echo line7 >>file1 &&
p4 submit -d "line7 in file1"
) &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
# this submit should cause a conflict
echo line8 >>file1 &&
git add file1 &&
git commit -m "line8 in file1 will conflict" &&
# but this commit is okay
test_commit "okay_commit_after_quit" &&
echo q | test_expect_code 1 git p4 submit >out &&
test_i18ngrep "No commits applied" out
)
'

test_expect_success 'kill p4d' '
kill_p4d
'
Expand Down

0 comments on commit 7e5dd9f

Please sign in to comment.