@matheusbsbs / matheus-bagliano / commits / 51a2640afd
Fork 0

Handle patch errors in git-p4 submit better.

Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed Apr 15, 2007 at 09:59 UTC 51a2640afdd12475642728dc3576966abe0dba6d
1 file changed +32 -6
contrib/fast-import/git-p4
+32 -6
@@ -244,7 +244,33 @@ class P4Submit(Command):
244 else:
245 die("unknown modifier %s for %s" % (modifier, path))
246
247 - system("git diff-tree -p --diff-filter=ACMRTUXB \"%s^\" \"%s\" | patch -p1" % (id, id))
247 + diffcmd = "git diff-tree -p --diff-filter=ACMRTUXB \"%s^\" \"%s\"" % (id, id)
248 + patchcmd = diffcmd + " | patch -p1"
249 +
250 + if os.system(patchcmd + " --dry-run --silent") != 0:
251 + print "Unfortunately applying the change failed!"
252 + print "What do you want to do?"
253 + response = "x"
254 + while response != "s" and response != "a" and response != "w":
255 + response = raw_input("[s]kip this patch / [a]pply the patch forcibly and with .rej files / [w]rite the patch to a file (patch.txt) ")
256 + if response == "s":
257 + print "Skipping! Good luck with the next patches..."
258 + return
259 + elif response == "a":
260 + os.system(patchcmd)
261 + if len(filesToAdd) > 0:
262 + print "You may also want to call p4 add on the following files:"
263 + print " ".join(filesToAdd)
264 + if len(filesToDelete):
265 + print "The following files should be scheduled for deletion with p4 delete:"
266 + print " ".join(filesToDelete)
267 + die("Please resolve and submit the conflict manually and continue afterwards with git-p4 submit --continue")
268 + elif response == "w":
269 + system(diffcmd + " > patch.txt")
270 + print "Patch saved to patch.txt in %s !" % self.clientPath
271 + die("Please resolve and submit the conflict manually and continue afterwards with git-p4 submit --continue")
272 +
273 + system(patchcmd)
274
275 for f in filesToAdd:
276 system("p4 add %s" % f)
@@ -335,16 +361,16 @@ class P4Submit(Command):
361 print "Internal error: cannot locate perforce depot path from existing branches"
362 sys.exit(128)
363
338 - clientPath = p4Where(depotPath)
364 + self.clientPath = p4Where(depotPath)
365
340 - if len(clientPath) == 0:
366 + if len(self.clientPath) == 0:
367 print "Error: Cannot locate perforce checkout of %s in client view" % depotPath
368 sys.exit(128)
369
344 - print "Perforce checkout for depot path %s located at %s" % (depotPath, clientPath)
370 + print "Perforce checkout for depot path %s located at %s" % (depotPath, self.clientPath)
371 oldWorkingDirectory = os.getcwd()
346 - os.chdir(clientPath)
347 - response = raw_input("Do you want to sync %s with p4 sync? [y]es/[n]o " % clientPath)
372 + os.chdir(self.clientPath)
373 + response = raw_input("Do you want to sync %s with p4 sync? [y]es/[n]o " % self.clientPath)
374 if response == "y" or response == "yes":
375 system("p4 sync ...")
376