def main(argv): 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' 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_git('branch', '--set-upstream-to', new_parent, branch) try: cmd = ['reup'] + (['--verbose'] if VERBOSE else []) run_git(*cmd, stdout=None, stderr=None) except: print "Resetting parent back to %s" % (cur_parent) run_git('branch', '--set-upstream-to', cur_parent, branch) raise return 0
def main(): if '--clean' in sys.argv: clean_refs() return 0 orig_branch = current_branch() if orig_branch == 'HEAD': orig_branch = git_hash('HEAD') if 'origin' in run_git('remote').splitlines(): run_git('fetch', 'origin', stderr=None) else: run_git('svn', 'fetch', stderr=None) branch_tree = {} for branch in branches(): parent = upstream(branch) if not parent: print 'Skipping %s: No upstream specified' % branch continue branch_tree[branch] = parent starting_refs = {} for branch, parent in branch_tree.iteritems(): starting_refs[branch] = get_or_create_merge_base_tag(branch, parent) if VERBOSE: pprint(branch_tree) pprint(starting_refs) # XXX There is a more efficient way to do this, but for now... while branch_tree: this_pass = [i for i in branch_tree.items() if i[1] not in branch_tree] for branch, parent in this_pass: clean_branch(branch, parent, starting_refs[branch]) del branch_tree[branch] clean_refs() bclean() if orig_branch in branches(): run_git('checkout', orig_branch) else: run_git('checkout', 'origin/master') return 0
def squash(): branch = current_branch() parent = upstream(branch) merge_base = get_or_create_merge_base_tag(branch, parent) run_git('reset', '--soft', merge_base) run_git('commit', '-a', '-C', 'HEAD@{1}')