def clean_branch(branch, parent, starting_ref): if (git_hash(parent) != git_hash(starting_ref) and git_hash(branch) != git_hash(starting_ref)): print 'Rebasing:', branch # Try a plain rebase first if rebase(parent, starting_ref, branch, abort=True).success: return # Maybe squashing will help? print "Failed! Attempting to squash", branch, "...", squash_branch = branch+"_squash_attempt" run_git('checkout', '-b', squash_branch) squash() squash_ret = rebase(parent, starting_ref, squash_branch, abort=True) run_git('checkout', branch) run_git('branch', '-D', squash_branch) if squash_ret.success: print 'Success!' squash() final_rebase = rebase(parent, starting_ref, branch) assert final_rebase.success == squash_ret.success if not squash_ret.success: print squash_ret.message print 'Failure :(' print 'Your working copy is in mid-rebase. Please completely resolve and' print 'run `git reup` again.' sys.exit(1)
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 finalize(target): """After calculating the generation number for |target|, call finalize to save all our work to the git repository. """ if not DIRTY_TREES: return msg = 'git-number Added %s numbers' % sum(DIRTY_TREES.itervalues()) idx = os.path.join(run_git('rev-parse', '--git-dir'), 'number.idx') env = {'GIT_INDEX_FILE': idx} with StatusPrinter('Finalizing: (%%d/%d)' % len(DIRTY_TREES)) as inc: run_git('read-tree', REF, env=env) prefixes_trees = ((p, get_num_tree(p)) for p in sorted(DIRTY_TREES)) updater = subprocess.Popen(['git', 'update-index', '-z', '--index-info'], stdin=subprocess.PIPE, env=env) with ScopedPool() as leaf_pool: for item in leaf_pool.imap(leaf_map_fn, prefixes_trees): updater.stdin.write(item) inc() updater.stdin.close() updater.wait() run_git('update-ref', REF, run_git('commit-tree', '-m', msg, '-p', git_hash(REF), '-p', target, run_git('write-tree', env=env)))
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