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