Index: git_reparent_branch.py |
diff --git a/git_reparent_branch.py b/git_reparent_branch.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..20ef4ffa71a92b7ed4c315d719a69959eac31f12 |
--- /dev/null |
+++ b/git_reparent_branch.py |
@@ -0,0 +1,35 @@ |
+#!/usr/bin/env python |
+import sys |
+ |
+from git_common import upstream, current_branch, run |
+from git_common import get_or_create_merge_base_tag |
+ |
+def main(argv): |
+ # TODO(iannucci): Add --verbose |
Ryan Tseng
2014/02/28 21:22:05
Add --help. "reparent branch" also isn't self evi
|
+ |
+ assert len(argv) == 2, "Must supply new parent" |
+ branch = current_branch() |
+ new_parent = argv[1] |
+ cur_parent = upstream(branch) |
+ assert branch != 'HEAD', 'Must be on the branch you want to reparent' |
agable
2014/02/28 20:14:16
Could let them specify the branch they want to rep
iannucci
2014/03/20 10:59:37
added TODO
|
+ assert cur_parent != new_parent |
+ |
+ get_or_create_merge_base_tag(branch, cur_parent) |
+ |
+ print "Reparenting %s to track %s (was %s)" % (branch, new_parent, cur_parent) |
+ run('branch', '--set-upstream-to', new_parent, branch) |
+ try: |
+ cmd = ['reup'] #+ (['--verbose'] if VERBOSE else []) |
+ run(*cmd, stdout=None, stderr=None) |
+ except: |
+ print "Resetting parent back to %s" % (cur_parent) |
+ run('branch', '--set-upstream-to', cur_parent, branch) |
+ raise |
+ |
+ return 0 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main(sys.argv)) |
+ |
+ |