def branches(prefix='', *args): root = GitRoot.root_container() pulls = Git.pull_branches() if not ARGS.expanded: fname = [''] def before(f): fname[0] = os.path.basename(f) def callback(data): parts = filter(None, data.splitlines()) for i, p in enumerate(parts): branch = p.split()[-1] if branch in pulls: branch += '(%s)' % pulls[branch] if p.startswith('*'): branch = '*' + branch parts[i] = branch print('%-12s %s' % (fname[0] + ':', ' '.join(parts))) Call.for_each_directory( BRANCH_COMMAND, path=root, select=GitRoot.select(prefix), before=before, callback=callback) else: def before(f): print('\n%s:' % os.path.basename(f)) Call.for_each_directory( BRANCH_COMMAND, path=root, select=GitRoot.select(prefix), before=before) if args: print('ERROR: arguments %s ignored' % ', '.join(args))
def _move_root(forward, prefix=''): root = GitRoot.ROOT container = GitRoot.root_container() roots = sorted(File.each(path=container, select=GitRoot.select(prefix))) if roots: try: index = roots.index(root) except ValueError: print(roots[0] if forward else roots[-1]) return index += (1 if forward else -1) path = roots[index % len(roots)] sub = os.path.join(path, os.path.relpath(os.getcwd(), root)) print((sub if os.path.exists(sub) else path) or '.') else: print('.')