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 <michael.horowitz@ieee.org> Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Dec 17, 2011 at 12:39 UTC d16520499d2652b5b59dfb25f9cf2d56a4c6913a
2 files changed +34 -8
contrib/fast-import/git-p4
+11 -7
@@ -872,13 +872,16 @@ class P4Submit(Command, P4UserMap):
872 if gitConfig("git-p4.skipSubmitEditCheck") == "true":
873 return True
874
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
885
886 def applyCommit(self, id):
887 print "Applying %s" % (read_pipe("git log --max-count=1 --pretty=oneline %s" % id))
@@ -1062,6 +1065,7 @@ class P4Submit(Command, P4UserMap):
1065 self.modifyChangelistUser(changelist, p4User)
1066 else:
1067 # skip this patch
1068 + print "Submission cancelled, undoing p4 changes."
1069 for f in editedFiles:
1070 p4_revert(f)
1071 for f in filesToAdd:
t/t9805-skip-submit-edit.sh
+23 -1
@@ -38,7 +38,7 @@ test_expect_success 'no config, unedited, say no' '
38 cd "$git" &&
39 echo line >>file1 &&
40 git commit -a -m "change 3 (not really)" &&
41 - printf "bad response\nn\n" | "$GITP4" submit
41 + printf "bad response\nn\n" | "$GITP4" submit &&
42 p4 changes //depot/... >wc &&
43 test_line_count = 2 wc
44 )
@@ -74,6 +74,28 @@ test_expect_success 'skipSubmitEditCheck' '
74 )
75 '
76
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 +'
99
100 test_expect_success 'kill p4d' '
101 kill_p4d