Skip to content

Commit d165204

Browse files
Pete Wyckoffgitster
authored andcommitted
git-p4: fix skipSubmitEdit regression
Commit 7c766e5 (git-p4: introduce skipSubmitEdit, 2011-12-04) made it easier to automate submission to p4, but broke the most common case. Add a test for when the user really does edit and save the change template, and fix the bug that causes the test to fail. Also add a confirmation message when submission is cancelled. Reported-by: Michael Horowitz <[email protected]> Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee22802 commit d165204

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

contrib/fast-import/git-p4

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,16 @@ class P4Submit(Command, P4UserMap):
872872
if gitConfig("git-p4.skipSubmitEditCheck") == "true":
873873
return True
874874

875-
if os.stat(template_file).st_mtime <= mtime:
876-
while True:
877-
response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
878-
if response == 'y':
879-
return True
880-
if response == 'n':
881-
return False
875+
# modification time updated means user saved the file
876+
if os.stat(template_file).st_mtime > mtime:
877+
return True
878+
879+
while True:
880+
response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
881+
if response == 'y':
882+
return True
883+
if response == 'n':
884+
return False
882885

883886
def applyCommit(self, id):
884887
print "Applying %s" % (read_pipe("git log --max-count=1 --pretty=oneline %s" % id))
@@ -1062,6 +1065,7 @@ class P4Submit(Command, P4UserMap):
10621065
self.modifyChangelistUser(changelist, p4User)
10631066
else:
10641067
# skip this patch
1068+
print "Submission cancelled, undoing p4 changes."
10651069
for f in editedFiles:
10661070
p4_revert(f)
10671071
for f in filesToAdd:

t/t9805-skip-submit-edit.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test_expect_success 'no config, unedited, say no' '
3838
cd "$git" &&
3939
echo line >>file1 &&
4040
git commit -a -m "change 3 (not really)" &&
41-
printf "bad response\nn\n" | "$GITP4" submit
41+
printf "bad response\nn\n" | "$GITP4" submit &&
4242
p4 changes //depot/... >wc &&
4343
test_line_count = 2 wc
4444
)
@@ -74,6 +74,28 @@ test_expect_success 'skipSubmitEditCheck' '
7474
)
7575
'
7676

77+
# check the normal case, where the template really is edited
78+
test_expect_success 'no config, edited' '
79+
"$GITP4" clone --dest="$git" //depot &&
80+
test_when_finished cleanup_git &&
81+
ed="$TRASH_DIRECTORY/ed.sh" &&
82+
test_when_finished "rm \"$ed\"" &&
83+
cat >"$ed" <<-EOF &&
84+
#!$SHELL_PATH
85+
sleep 1
86+
touch "\$1"
87+
exit 0
88+
EOF
89+
chmod 755 "$ed" &&
90+
(
91+
cd "$git" &&
92+
echo line >>file1 &&
93+
git commit -a -m "change 5" &&
94+
EDITOR="\"$ed\"" "$GITP4" submit &&
95+
p4 changes //depot/... >wc &&
96+
test_line_count = 5 wc
97+
)
98+
'
7799

78100
test_expect_success 'kill p4d' '
79101
kill_p4d

0 commit comments

Comments
 (0)