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