##// END OF EJS Templates
Make Yes the default for git-mrb, fits regular workflow much better.
Fernando Perez -
Show More
@@ -1,80 +1,80 b''
1 1 #!/usr/bin/env python
2 2 """git-mrb: merge remote branch.
3 3
4 4 git mrb [remote:branch OR remote-branch] [onto] [upstream]
5 5
6 6 remote must be locally available, and branch must exist in that remote.
7 7
8 8 If 'onto' branch isn't given, default is 'master'.
9 9
10 10 If 'upstream' repository isn't given, default is 'origin'.
11 11
12 12 You can separate the remote and branch spec with either a : or a -.
13 13 """
14 14 #-----------------------------------------------------------------------------
15 15 # Imports
16 16 #-----------------------------------------------------------------------------
17 17
18 18 from subprocess import check_call
19 19 import sys
20 20
21 21 #-----------------------------------------------------------------------------
22 22 # Functions
23 23 #-----------------------------------------------------------------------------
24 24
25 25 def sh(cmd):
26 26 cmd = cmd.format(**shvars)
27 27 print '$', cmd
28 28 check_call(cmd, shell=True)
29 29
30 30 #-----------------------------------------------------------------------------
31 31 # Main Script
32 32 #-----------------------------------------------------------------------------
33 33
34 34 argv = sys.argv[1:]
35 35 narg = len(argv)
36 36
37 37 try:
38 38 branch_spec = argv[0]
39 39 sep = ':' if ':' in branch_spec else '-'
40 40 remote, branch = branch_spec.split(':', 1)
41 41 if not branch:
42 42 raise ValueError('Branch spec %s invalid, branch not found' %
43 43 branch_spec)
44 44 except:
45 45 import traceback as tb
46 46 tb.print_exc()
47 47 print __doc__
48 48 sys.exit(1)
49 49
50 50 onto = argv[1] if narg >= 2 else 'master'
51 51 upstream = argv[1] if narg == 3 else 'origin'
52 52
53 53 # Git doesn't like ':' in branch names.
54 54 if sep == ':':
55 55 branch_spec = branch_spec.replace(':', '-')
56 56
57 57 # Global used by sh
58 58 shvars = dict(remote=remote, branch_spec=branch_spec, branch=branch,
59 59 onto=onto, upstream=upstream)
60 60
61 61 # Start git calls.
62 62 sh('git fetch {remote}')
63 63 sh('git checkout -b {branch_spec} {onto}')
64 64 sh('git merge {remote}/{branch}')
65 65
66 66 print """
67 67 *************************************************************
68 68 Run test suite. If tests pass, run the following to merge:
69 69
70 70 git checkout {onto}
71 71 git merge {branch_spec}
72 72 git push {upstream} {onto}
73 73
74 74 *************************************************************
75 75 """.format(**shvars)
76 76
77 ans = raw_input("Revert to master and delete temporary branch? [y/N]: ")
78 if ans.lower() in ('y', 'yes'):
77 ans = raw_input("Revert to master and delete temporary branch? [Y/n]: ")
78 if ans.strip().lower() in ('', 'y', 'yes'):
79 79 sh('git checkout {onto}')
80 80 sh('git branch -D {branch_spec}')
General Comments 0
You need to be logged in to leave comments. Login now