2

I use vimdiff as my merge tool in mercurial. Sometimes I'll start a rebase that ends up being pretty messy and I just want to try and get out of the process and do something different. The way I end up doing this is usually just spamming :qa until I've made my way through all the conflicting files, but for larger sets of conflicts this can mean I'm doing that for quite a while. Sometimes, if I'm lucky, I can sneak in Ctrl+C in the time before the next conflict loads up in vim, but often I just end up messing something even bigger up and my whole terminal session is hosed.

Is there a more graceful way of quitting out of a messy rebase when using vimdiff?

Ziewvater
  • 1,413
  • 1
  • 18
  • 33

2 Answers2

3

From vimdiff, you can use the :cq command to quit Vim with an error code.

Mercurial should be able to tell that this happened and interpret as you telling it to stop the operation, giving you the opportunity to break the merge operation.

filbranden
  • 8,522
  • 2
  • 16
  • 32
  • 1
    Unfortunately this didn't work. It will quit out and fail the file I'm currently attempting to merge, but then mercurial moves on very quickly to the next conflict. – Ziewvater Mar 14 '20 at 13:51
  • @Ziewvater Ah, bummer... It's made specifically for this kind of occasion where you need to tell it to stop and break. A pity that Mercurial doesn't seem to handle it that way. How about the other way I suggested with the Ctrl+Z? – filbranden Mar 14 '20 at 14:00
  • 1
    Just commented about that! It works much better, though it's not entirely clean. That might be because of the other wrapper tools I'm working with, I'm not sure, but it's far more manageable – Ziewvater Mar 14 '20 at 14:36
1

You can use Ctrl+Z to suspend the foreground process (which is vimdiff, but also the hg that spawned it), dropping you back to the shell.

At this point, you can kill the foreground job with kill %%, or perhaps kill -INT %% (SIGINT is equivalent to pressing Ctrl+C), which should kill the hg process and terminate vimdiff with a SIGHUP (Hang-Up).

By suspending vimdiff, you manage to find the time to send hg the equivalent of a Ctrl+C.

filbranden
  • 8,522
  • 2
  • 16
  • 32
  • 1
    I still end up with some process holding onto a lock for a file when I try to run `hg rebase --abort` after doing this, but it's a much better process than what I was doing before. I'm able to free up the lock by killing the PID named when `hg rebase --abort` gets stuck, and `kill`ing the other leftover processes. – Ziewvater Mar 14 '20 at 14:34