git p4: test clean-up after failed submit, fix added files

Test a variety of cases where a patch failed to apply to p4 and had to be cleaned up. If the patch failed to apply cleanly, do not try to remove to-be-added files, as they have not really been added yet. Signed-off-by: Pete Wyckoff <pw@padd.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Sep 9, 2012 at 16:16 UTC f7fbc981a4effde51446c2229e34f2fc9210d31d
2 files changed +132 -2
git-p4.py
-2
@@ -1200,8 +1200,6 @@ class P4Submit(Command, P4UserMap):
1200 if not patch_succeeded:
1201 for f in editedFiles:
1202 p4_revert(f)
1203 - for f in filesToAdd:
1204 - os.remove(f)
1203 return False
1204
1205 system(applyPatchCmd)
t/t9815-git-p4-submit-fail.sh
+132
@@ -108,6 +108,138 @@ test_expect_success 'conflict on first of two commits, quit' '
108 )
109 '
110
111 +#
112 +# Cleanup after submit fail, all cases. Some modifications happen
113 +# before trying to apply the patch. Make sure these are unwound
114 +# properly. Put each one in a diff along with something that will
115 +# obviously conflict. Make sure it is back to normal after.
116 +#
117 +
118 +test_expect_success 'cleanup edit p4 populate' '
119 + (
120 + cd "$cli" &&
121 + echo text file >text &&
122 + p4 add text &&
123 + echo text+x file >text+x &&
124 + chmod 755 text+x &&
125 + p4 add text+x &&
126 + p4 submit -d "populate p4"
127 + )
128 +'
129 +
130 +setup_conflict() {
131 + # clone before modifying file1 to force it to conflict
132 + test_when_finished cleanup_git &&
133 + git p4 clone --dest="$git" //depot &&
134 + # ticks outside subshells
135 + test_tick &&
136 + (
137 + cd "$cli" &&
138 + p4 open file1 &&
139 + echo $test_tick >>file1 &&
140 + p4 submit -d "$test_tick in file1"
141 + ) &&
142 + test_tick &&
143 + (
144 + cd "$git" &&
145 + git config git-p4.skipSubmitEdit true &&
146 + # easy conflict
147 + echo $test_tick >>file1 &&
148 + git add file1
149 + # caller will add more and submit
150 + )
151 +}
152 +
153 +test_expect_success 'cleanup edit after submit fail' '
154 + setup_conflict &&
155 + (
156 + cd "$git" &&
157 + echo another line >>text &&
158 + git add text &&
159 + git commit -m "conflict" &&
160 + test_expect_code 1 git p4 submit
161 + ) &&
162 + (
163 + cd "$cli" &&
164 + # make sure it is not open
165 + ! p4 fstat -T action text
166 + )
167 +'
168 +
169 +test_expect_success 'cleanup add after submit fail' '
170 + setup_conflict &&
171 + (
172 + cd "$git" &&
173 + echo new file >textnew &&
174 + git add textnew &&
175 + git commit -m "conflict" &&
176 + test_expect_code 1 git p4 submit
177 + ) &&
178 + (
179 + cd "$cli" &&
180 + # make sure it is not there
181 + # and that p4 thinks it is not added
182 + # P4 returns 0 both for "not there but added" and
183 + # "not there", so grep.
184 + test_path_is_missing textnew &&
185 + p4 fstat -T action textnew 2>&1 | grep "no such file"
186 + )
187 +'
188 +
189 +test_expect_success 'cleanup delete after submit fail' '
190 + setup_conflict &&
191 + (
192 + cd "$git" &&
193 + git rm text+x &&
194 + git commit -m "conflict" &&
195 + test_expect_code 1 git p4 submit
196 + ) &&
197 + (
198 + cd "$cli" &&
199 + # make sure it is there
200 + test_path_is_file text+x &&
201 + ! p4 fstat -T action text+x
202 + )
203 +'
204 +
205 +test_expect_success 'cleanup copy after submit fail' '
206 + setup_conflict &&
207 + (
208 + cd "$git" &&
209 + cp text text2 &&
210 + git add text2 &&
211 + git commit -m "conflict" &&
212 + git config git-p4.detectCopies true &&
213 + git config git-p4.detectCopiesHarder true &&
214 + # make sure setup is okay
215 + git diff-tree -r -C --find-copies-harder HEAD | grep text2 | grep C100 &&
216 + test_expect_code 1 git p4 submit
217 + ) &&
218 + (
219 + cd "$cli" &&
220 + test_path_is_missing text2 &&
221 + p4 fstat -T action text2 2>&1 | grep "no such file"
222 + )
223 +'
224 +
225 +test_expect_success 'cleanup rename after submit fail' '
226 + setup_conflict &&
227 + (
228 + cd "$git" &&
229 + git mv text text2 &&
230 + git commit -m "conflict" &&
231 + git config git-p4.detectRenames true &&
232 + # make sure setup is okay
233 + git diff-tree -r -M HEAD | grep text2 | grep R100 &&
234 + test_expect_code 1 git p4 submit
235 + ) &&
236 + (
237 + cd "$cli" &&
238 + test_path_is_missing text2 &&
239 + p4 fstat -T action text2 2>&1 | grep "no such file"
240 + )
241 +'
242 +
243 test_expect_success 'kill p4d' '
244 kill_p4d
245 '