@matheusbsbs / matheus-bagliano / commits / 9512497bcf
Fork 0

Make it possible to run git-p4 submit from within the git repository

Signed-off-by: Simon Hausmann <hausmann@kde.org>

Simon Hausmann committed Mar 23, 2007 at 09:16 UTC 9512497bcf574a2f70e43be0bcb58e35fb6aaba8
2 files changed +50 -15
contrib/fast-import/git-p4
+37 -1
@@ -162,7 +162,7 @@ class P4Sync(Command):
162 self.dryRun = False
163 self.substFile = ""
164 self.firstTime = True
165 - self.origin = "origin"
165 + self.origin = ""
166 self.master = ""
167 self.applyAsPatch = True
168
@@ -304,6 +304,42 @@ class P4Sync(Command):
304 print "Perforce submit template written as %s. Please review/edit and then use p4 submit -i < %s to submit directly!" % (fileName, fileName)
305
306 def run(self, args):
307 + global gitdir
308 + # make gitdir absolute so we can cd out into the perforce checkout
309 + gitdir = os.path.abspath(gitdir)
310 + os.environ["GIT_DIR"] = gitdir
311 + depotPath = ""
312 + if gitBranchExists("p4"):
313 + [depotPath, dummy] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("p4"))
314 + if len(depotPath) == 0 and gitBranchExists("origin"):
315 + [depotPath, dummy] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("origin"))
316 +
317 + if len(depotPath) == 0:
318 + print "Internal error: cannot locate perforce depot path from existing branches"
319 + sys.exit(128)
320 +
321 + if not depotPath.endswith("/"):
322 + depotPath += "/"
323 + clientPath = p4Cmd("where %s..." % depotPath).get("path")
324 + if clientPath.endswith("..."):
325 + clientPath = clientPath[:-3]
326 +
327 + if len(clientPath) == 0:
328 + print "Error: Cannot locate perforce checkout of %s in client view" % depotPath
329 + sys.exit(128)
330 +
331 + print "Perforce checkout for depot path %s located at %s" % (depotPath, clientPath)
332 + os.chdir(clientPath)
333 + response = raw_input("Do you want to sync %s with p4 sync? (y/n)" % clientPath)
334 + if response == "y" or response == "yes":
335 + system("p4 sync ...")
336 +
337 + if len(self.origin) == 0:
338 + if gitBranchExists("p4"):
339 + self.origin = "p4"
340 + else:
341 + self.origin = "origin"
342 +
343 if self.reset:
344 self.firstTime = True
345
contrib/fast-import/git-p4.txt
+13 -14
@@ -51,28 +51,27 @@ Submitting
51
52 git-p4 has EXPERIMENTAL support for submitting changes from a git repository
53 back to a Perforce depot. This requires a Perforce checkout separate to your
54 -git repository. This is the basic procedure:
54 +git repository. All it should take is calling
55
56 - cd path/to/your/perforce/checkout
57 - git-p4 submit --git-dir=/path/to/your/git/repository
56 + git-p4 submit
57
59 -This will create a temporary git branch, use git-rev-list to find out which git
60 -commits are in your current branch but not in the "origin" branch. You can
61 -override the name of the "origin" branch by using the --origin=mybranch option.
62 -The "origin" branch has to be the branch populated with git-p4's sync
63 -operation.
58 +in your git repository. This will attempt to locate the perforce checkout
59 +corresponding to your imported depot path. By default the changes between your
60 +current branch and the "p4" branch will be submitted. If there is no "p4"
61 +branch the "origin" branch will be used as reference instead. You can override
62 +this with the --origin=mysourcebranch option. The "origin" branch has to be the
63 +branch populated with git-p4's sync operation.
64
65 After some preparations (which might take a while) git-p4 enters a loop where
66 it will first show a Perforce submit template and a diff of the change to
67 -apply. After quitting the pager with 'q' git-p4 asks for confirmation for
68 -issuing the "p4 submit" command and also gives you the option of editing the
69 -submit template using "e".
67 +apply in the editor. After saving and exiting the editor you will be asked whether
68 +you really want to submit the change or not.
69
70 If a submit fails you may have to "p4 resolve" and submit manually. You can
71 continue importing the remaining changes with
72
74 - git-p4 submit --git-dir=/path/to/your/git/repository --continue
73 + git-p4 submit --continue
74
76 -After submitting you should sync your origin branch from Perforce using
77 -git-p4's sync command.
75 +After submitting you should sync your perforce import branch ("p4" or "origin")
76 +from Perforce using git-p4's sync command.
77