def main(argv): assert len(argv) == 1, "No arguments expected" upfn = upstream cur = current_branch() if cur == "HEAD": upfn = lambda b: git_hash(upstream(b)) cur = git_hash(cur) downstreams = [b for b in branches() if upfn(b) == cur] if not downstreams: return "No downstream branches" elif len(downstreams) == 1: run_git("checkout", downstreams[0]) else: high = len(downstreams) - 1 print while True: print "Please select a downstream branch" for i, b in enumerate(downstreams): print " %d. %s" % (i, b) r = raw_input("Selection (0-%d)[0]: " % high).strip() or "0" if not r.isdigit() or (0 > int(r) > high): print "Invalid choice." else: run_git("checkout", downstreams[int(r)]) break
def bclean(): merged = list(branches('--merged', 'origin/master')) if VERBOSE: print merged upstreams = {} downstreams = collections.defaultdict(list) for branch in branches(): try: parent = upstream(branch) upstreams[branch] = parent downstreams[parent].append(branch) except CalledProcessError: pass if VERBOSE: print upstreams print downstreams if current_branch() in merged: run_git('checkout', 'origin/master') for branch in merged: for down in downstreams[branch]: if down not in merged: run_git('branch', '--set-upstream-to', upstreams[branch], down) print ('Reparented %s to track %s (was tracking %s)' % (down, upstreams[branch], branch)) print run_git('branch', '-d', branch) 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 main(argv): assert len(argv) == 1, "No arguments expected" branch_map = {} par_map = collections.defaultdict(list) for branch in branches(): par = upstream(branch) branch_map[branch] = par par_map[par].append(branch) current = current_branch() hashes = git_hashes(current, *branch_map.keys()) current_hash = hashes[0] par_hashes = {k: hashes[i+1] for i, k in enumerate(branch_map.iterkeys())} while par_map: for parent in par_map: if parent not in branch_map: if parent not in par_hashes: par_hashes[parent] = git_hash(parent) print_branch(current, current_hash, parent, par_hashes, par_map, branch_map) break
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 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}')