feature request: abort subcommand
#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-imergecreates usinggit-imerge remove, then checkout the branch you were in before you started the incremental merge withgit 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).
It would be nice to have a
git imerge abortcommand 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 returnsNoneif the user is on a detached HEAD. (What should happen if the user runsgit imerge abortafter 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
statedict byMergeRecord.save()so that it can be remembered across invocations, and read back in byMergeRecord.read(). This change should probably be accompanied by an increment ofSTATE_VERSION[2]. -
git imerge abortshould 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 inMergeState.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.
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 abortshould 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.