@matheusbsbs / matheus-bagliano / commits / 7944f1425c
Fork 0

Make git-p4 submit --direct safer by also creating a git commit

Signed-off-by: Simon Hausmann <shausman@trolltech.com>

Simon Hausmann committed May 21, 2007 at 11:04 UTC 7944f1425c0665eef6a5b9f5cc92e15cddb42984
1 file changed +14 -20
contrib/fast-import/git-p4
+14 -20
@@ -10,12 +10,6 @@
10 # TODO: * implement git-p4 rollback <perforce change number> for debugging
11 # to roll back all p4 remote branches to a commit older or equal to
12 # the specified change.
13 -# * for git-p4 submit --direct it would be nice to still create a
14 -# git commit without updating HEAD before submitting to perforce.
15 -# With the commit sha1 printed (or recoded in a .git/foo file?)
16 -# it's possible to recover if anything goes wrong instead of potentially
17 -# loosing a change entirely because it was never comitted to git and
18 -# the p4 submit failed (or resulted in lots of conflicts, etc.)
13 # * Consider making --with-origin the default, assuming that the git
14 # protocol is always more efficient. (needs manual testing first :)
15 #
@@ -328,9 +322,17 @@ class P4Submit(Command):
322 print submitTemplate
323 raw_input("Press return to continue...")
324 else:
331 - pipe = os.popen("p4 submit -i", "wb")
332 - pipe.write(submitTemplate)
333 - pipe.close()
325 + if self.directSubmit:
326 + print "Submitting to git first"
327 + os.chdir(self.oldWorkingDirectory)
328 + pipe = os.popen("git commit -a -F -", "wb")
329 + pipe.write(submitTemplate)
330 + pipe.close()
331 + os.chdir(self.clientPath)
332 +
333 + pipe = os.popen("p4 submit -i", "wb")
334 + pipe.write(submitTemplate)
335 + pipe.close()
336 elif response == "s":
337 for f in editedFiles:
338 system("p4 revert \"%s\"" % f);
@@ -382,7 +384,7 @@ class P4Submit(Command):
384 sys.exit(128)
385
386 print "Perforce checkout for depot path %s located at %s" % (depotPath, self.clientPath)
385 - oldWorkingDirectory = os.getcwd()
387 + self.oldWorkingDirectory = os.getcwd()
388
389 if self.directSubmit:
390 self.diffStatus = mypopen("git diff -r --name-status HEAD").readlines()
@@ -442,16 +444,8 @@ class P4Submit(Command):
444 print "No changes found to apply between %s and current HEAD" % self.origin
445 else:
446 print "All changes applied!"
445 - response = ""
446 - os.chdir(oldWorkingDirectory)
447 -
448 - if self.directSubmit:
449 - response = raw_input("Do you want to DISCARD your git WORKING DIRECTORY CHANGES and sync from Perforce now using git-p4 rebase? [y]es/[n]o ")
450 - if response == "y" or response == "yes":
451 - system("git reset --hard")
452 -
453 - if len(response) == 0:
454 - response = raw_input("Do you want to sync from Perforce now using git-p4 rebase? [y]es/[n]o ")
447 + os.chdir(self.oldWorkingDirectory)
448 + response = raw_input("Do you want to sync from Perforce now using git-p4 rebase? [y]es/[n]o ")
449 if response == "y" or response == "yes":
450 rebase = P4Rebase()
451 rebase.run([])