def get_ahead_behind(lbranch: str, rbranch: str) -> Tuple[int, int]:
"""Return number of commits |lbranch| is ahead & behind relative to |rbranch|."""
output = git(
- ['rev-list', '--left-right', '--count', f'{lbranch}...{rbranch}']).stdout
+ ['rev-list', '--first-parent', '--left-right', '--count',
+ f'{lbranch}...{rbranch}']).stdout
return [int(x) for x in output.split()]
opts = parser.parse_args(argv)
lbranch = get_local_branch()
- print(f'Local branch resolved to "{lbranch}"')
+ print(f'Local branch resolved to "{lbranch}".')
if not lbranch:
print('Unable to resolve local branch', file=sys.stderr)
return 1
rbranch = opts.branch
else:
rbranch = get_tracking_branch(lbranch)
- print(f'Tracking branch resolved to "{rbranch}"')
+ print(f'Tracking branch resolved to "{rbranch}".')
ahead, behind = get_ahead_behind(lbranch, rbranch)
- print(f'Branch is {ahead} commits ahead and {behind} commits behind')
+ print(f'Branch is {ahead} commits ahead and {behind} commits behind.')
+ print('NB: Counts for the first parent in merge history, not all commits.')
if not behind:
print('Up-to-date!')