@matheusbsbs / matheus-bagliano / commits / d566209e7f
Fork 0

Auto-detect the current git branch before submitting back to perforce.

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

Simon Hausmann committed Mar 14, 2007 at 23:30 UTC d566209e7fecffb61a3209766cc937bf027e2c6c
1 file changed +11 -4
contrib/fast-import/p4-git-sync.py
+11 -4
@@ -33,6 +33,10 @@ def p4Cmd(cmd):
33 result.update(entry)
34 return result;
35
36 +def die(msg):
37 + sys.stderr.write(msg + "\n")
38 + sys.exit(1)
39 +
40 try:
41 opts, args = getopt.getopt(sys.argv[1:], "", [ "continue", "git-dir=", "origin=", "reset", "master=",
42 "submit-log-subst=", "log-substitutions=", "interactive",
@@ -46,7 +50,7 @@ logSubstitutions["<enter description here>"] = "%log%"
50 logSubstitutions["\tDetails:"] = "\tDetails: %log%"
51 gitdir = os.environ.get("GIT_DIR", "")
52 origin = "origin"
49 -master = "master"
53 +master = ""
54 firstTime = True
55 reset = False
56 interactive = False
@@ -88,9 +92,12 @@ origin = "origin"
92 if len(args) == 1:
93 origin = args[0]
94
91 -def die(msg):
92 - sys.stderr.write(msg + "\n")
93 - sys.exit(1)
95 +if len(master) == 0:
96 + sys.stdout.write("Auto-detecting current branch: ")
97 + master = os.popen("git-name-rev HEAD").read().split(" ")[1][:-1]
98 + if len(master) == 0 or not os.path.exists("%s/refs/heads/%s" % (gitdir, master)):
99 + die("\nFailed to detect current branch! Aborting!");
100 + sys.stdout.write("%s\n" % master)
101
102 def system(cmd):
103 if os.system(cmd) != 0: