PROG = os.path.basename(__file__)
+DEBUG = False
class Terminal:
return cls.BAD + msg + cls.NORMAL
+def dbg(msg):
+ """Print a debug |msg|."""
+ if DEBUG:
+ print(msg, file=sys.stderr)
+
+
def fatal(msg):
"""Show an error |msg| then exit."""
print(Color.bad(f'{PROG}: error: {msg}'), file=sys.stderr)
kwargs.setdefault('stdout', subprocess.PIPE)
kwargs.setdefault('stderr', subprocess.STDOUT)
kwargs.setdefault('encoding', 'utf-8')
- #print('+', 'git', *args)
+ if DEBUG:
+ print('+', 'git', *args)
return subprocess.run(['git'] + args, **kwargs)
parser.add_argument(
'--catchup', action='store_true',
help='run git-rb-catchup when rebasing')
+ parser.add_argument(
+ '-d', '--debug', action='store_true',
+ help='enable debug output')
parser.add_argument(
'-q', '--quiet', dest='git_options', action=AppendOption, default=['-q'],
help='passthru to git rebase')
parser = get_parser()
opts = parser.parse_args(argv)
+ global DEBUG
+ DEBUG = opts.debug
+
# Switch to the top dir in case the working dir doesn't exist in every branch.
- topdir = git(['rev-parse', '--show-toplevel']).stdout.strip()
+ try:
+ topdir = git(['rev-parse', '--show-toplevel'], stderr=subprocess.PIPE).stdout.strip()
+ except subprocess.CalledProcessError as e:
+ sys.exit(f'{os.path.basename(sys.argv[0])}: {Path.cwd()}:\n{e}\n{e.stderr.strip()}')
os.chdir(topdir)
# Example output:
branch_width = max(branch_width, len(branch))
if head == '*':
curr_state = branch
- if not (worktreepath and worktreepath != topdir):
local_count += 1
+ elif not (worktreepath and worktreepath != topdir):
+ local_count += 1
+ else:
+ dbg(f'{worktreepath}:{branch}: Skipping branch checked out in diff worktree')
# If there are no branches to rebase, go silently.
if not local_count:
return 0