git-imerge icon indicating copy to clipboard operation
git-imerge copied to clipboard

feature request: abort subcommand

Open waldyrious opened this issue 8 years ago • 2 comments

#97 introduced instructions in the README to abort a git-imerge operation (after the prompt in #95):

If you need to completely abort an in-progress incremental merge, first remove the temporary branches git-imerge creates using git-imerge remove, then checkout the branch you were in before you started the incremental merge with git checkout ORIGINAL_BRANCH.

It would be nice to have a git imerge abort command that did this automatically.

I could take a stab at this, but I'd need some pointers first (namely, how to get the branch the user was on before starting git-imerge).

waldyrious avatar Apr 18 '17 10:04 waldyrious

It would be nice to have a git imerge abort command that did this automatically.

Yes, that would be very nice.

I could take a stab at this, but I'd need some pointers first (namely, how to get the branch the user was on before starting git-imerge).

  • The branch name would have to be determined when the imerge is started by calling get_head_refname(short=True). Note that this function returns None if the user is on a detached HEAD. (What should happen if the user runs git imerge abort after having been on a detached HEAD? Maybe nothing? Maybe restore to the SHA-1 that they were on (if it still exists)?)
  • The branch name would have to be recorded in MergeRecord.
  • It would have to be added to the state dict by MergeRecord.save() so that it can be remembered across invocations, and read back in by MergeRecord.read(). This change should probably be accompanied by an increment of STATE_VERSION[2].
  • git imerge abort should only switch back to the starting branch if it still exists, if the working tree is clean, and perhaps only if the temporary branch is currently checked out. The code in MergeState.remove() might give you some ideas about this. For backwards compatibility, the code should deal gracefully with the situation that the starting branch wasn't recorded in the state.

mhagger avatar Apr 18 '17 13:04 mhagger

That's very thorough, thanks!

What should happen if the user runs git imerge abort after having been on a detached HEAD? Maybe nothing? Maybe restore to the SHA-1 that they were on (if it still exists)?)

As a user, I'd expect the latter.

git imerge abort should only switch back to the starting branch if it still exists, if the working tree is clean, and perhaps only if the temporary branch is currently checked out.

Sounds reasonable to me.

I've only dabbled with Python programming with small, one-off scripts, and local fixes to larger programs, so I'll try to set aside some time to attempt an implementation in the next few days, and submit it as a PR for further feedback and refinement.

waldyrious avatar Apr 18 '17 14:04 waldyrious