- git(['update-ref', f'refs/heads/{branch}', tracking])
- print('fast forwarded')
+ # If we haven't switched the checkout, update-ref on current HEAD
+ # will get us into a dirty checkout, so use merge to handle it.
+ if switched_head or curr_state != branch:
+ git(['update-ref', f'refs/heads/{branch}', tracking])
+ print('fast forwarded [updated ref]')
+ else:
+ result = git(['merge', '-q', '--ff-only'], check=False)
+ if result.returncode:
+ print(f'{Color.BAD}unable to merge{Color.NORMAL}\n' + result.stdout.strip())
+ else:
+ print('fast forwarded [merged]')