Give branches a nice project prefix and don't bail out on clone if we failed to detect the master branch.
Give branches a nice project prefix and don't bail out on clone if we failed to detect the master branch. Signed-off-by: Simon Hausmann <shausman@trolltech.com>
Simon Hausmann committed
May 18, 2007 at 22:13 UTC
8f9b2e082b54787676bdad793ca013ba4fb4e407
1 file changed
+18
-3
contrib/fast-import/git-p4
+18
-3
@@ -729,6 +729,7 @@ class P4Sync(Command):
729
730
if self.detectBranches:
731
self.getBranchMapping();
732
+ self.branchPrefix = self.depotPath[self.depotPath[:-1].rfind("/") + 1:]
733
734
self.tz = "%+03d%02d" % (- time.timezone / 3600, ((- time.timezone % 3600) / 60))
735
@@ -815,12 +816,23 @@ class P4Sync(Command):
816
817
filesForCommit = self.extractFilesInCommitToBranch(files, branch)
818
818
- if branch not in self.createdBranches :
819
+ if branch not in self.createdBranches:
820
self.createdBranches.add(branch)
821
parent = self.knownBranches[branch]
822
if parent == branch:
823
parent = ""
824
825
+ # main branch? use master
826
+ if branch == "main":
827
+ branch = "master"
828
+ else:
829
+ branch = self.branchPrefix + branch
830
+
831
+ if parent == "main":
832
+ parent = "master"
833
+ elif len(parent) > 0:
834
+ parent = self.branchPrefix + parent
835
+
836
branch = "refs/remotes/p4/" + branch
837
if len(parent) > 0:
838
parent = "refs/remotes/p4/" + parent
@@ -906,8 +918,11 @@ class P4Clone(P4Sync):
918
if not P4Sync.run(self, [depotPath]):
919
return False
920
if self.branch != "master":
909
- system("git branch master p4")
910
- system("git checkout -f")
921
+ if gitBranchExists("refs/remotes/p4/master"):
922
+ system("git branch master refs/remotes/p4/master")
923
+ system("git checkout -f")
924
+ else:
925
+ print "Could not detect main branch. No checkout/master branch created."
926
return True
927
928
class HelpFormatter(optparse.IndentedHelpFormatter):