Skip to content

Commit 7e5dd9f

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4: move conflict prompt into run, add [q]uit input
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 <[email protected]> Acked-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 449bb9c commit 7e5dd9f

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

git-p4.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,17 +1198,11 @@ def applyCommit(self, id):
11981198
patch_succeeded = True
11991199

12001200
if not patch_succeeded:
1201-
print "What do you want to do?"
1202-
response = "x"
1203-
while response != "s":
1204-
response = raw_input("[s]kip this patch ")
1205-
if response == "s":
1206-
print "Skipping! Good luck with the next patches..."
1207-
for f in editedFiles:
1208-
p4_revert(f)
1209-
for f in filesToAdd:
1210-
os.remove(f)
1211-
return False
1201+
for f in editedFiles:
1202+
p4_revert(f)
1203+
for f in filesToAdd:
1204+
os.remove(f)
1205+
return False
12121206

12131207
system(applyPatchCmd)
12141208

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

1472+
#
1473+
# Apply the commits, one at a time. On failure, ask if should
1474+
# continue to try the rest of the patches, or quit.
1475+
#
14781476
applied = []
1479-
for commit in commits:
1477+
last = len(commits) - 1
1478+
for i, commit in enumerate(commits):
14801479
ok = self.applyCommit(commit)
14811480
if ok:
14821481
applied.append(commit)
1482+
else:
1483+
if i < last:
1484+
quit = False
1485+
while True:
1486+
print "What do you want to do?"
1487+
response = raw_input("[s]kip this commit but apply"
1488+
" the rest, or [q]uit? ")
1489+
if not response:
1490+
continue
1491+
if response[0] == "s":
1492+
print "Skipping this commit, but applying the rest"
1493+
break
1494+
if response[0] == "q":
1495+
print "Quitting"
1496+
quit = True
1497+
break
1498+
if quit:
1499+
break
14831500

14841501
chdir(self.oldWorkingDirectory)
14851502

t/t9815-git-p4-submit-fail.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_expect_success 'init depot' '
1818
)
1919
'
2020

21-
test_expect_success 'conflict on one commit, skip' '
21+
test_expect_success 'conflict on one commit' '
2222
test_when_finished cleanup_git &&
2323
git p4 clone --dest="$git" //depot &&
2424
(
@@ -34,12 +34,12 @@ test_expect_success 'conflict on one commit, skip' '
3434
echo line3 >>file1 &&
3535
git add file1 &&
3636
git commit -m "line3 in file1 will conflict" &&
37-
echo s | test_expect_code 1 git p4 submit >out &&
37+
test_expect_code 1 git p4 submit >out &&
3838
test_i18ngrep "No commits applied" out
3939
)
4040
'
4141

42-
test_expect_success 'conflict on second of two commits, skip' '
42+
test_expect_success 'conflict on second of two commits' '
4343
test_when_finished cleanup_git &&
4444
git p4 clone --dest="$git" //depot &&
4545
(
@@ -57,7 +57,7 @@ test_expect_success 'conflict on second of two commits, skip' '
5757
echo line4 >>file1 &&
5858
git add file1 &&
5959
git commit -m "line4 in file1 will conflict" &&
60-
echo s | test_expect_code 1 git p4 submit >out &&
60+
test_expect_code 1 git p4 submit >out &&
6161
test_i18ngrep "Applied only the commits" out
6262
)
6363
'
@@ -85,6 +85,29 @@ test_expect_success 'conflict on first of two commits, skip' '
8585
)
8686
'
8787

88+
test_expect_success 'conflict on first of two commits, quit' '
89+
test_when_finished cleanup_git &&
90+
git p4 clone --dest="$git" //depot &&
91+
(
92+
cd "$cli" &&
93+
p4 open file1 &&
94+
echo line7 >>file1 &&
95+
p4 submit -d "line7 in file1"
96+
) &&
97+
(
98+
cd "$git" &&
99+
git config git-p4.skipSubmitEdit true &&
100+
# this submit should cause a conflict
101+
echo line8 >>file1 &&
102+
git add file1 &&
103+
git commit -m "line8 in file1 will conflict" &&
104+
# but this commit is okay
105+
test_commit "okay_commit_after_quit" &&
106+
echo q | test_expect_code 1 git p4 submit >out &&
107+
test_i18ngrep "No commits applied" out
108+
)
109+
'
110+
88111
test_expect_success 'kill p4d' '
89112
kill_p4d
90113
'

0 commit comments

Comments
 (0)