2

When using mercurial, I know we can use hg commit --interactive to select which chunks of which files to commit. Is there any way to do this non-interactively, perhaps by preparing a patch file then applying it?

I'm thinking of making a vim plugin to handle mercurial commits, and it would be nice if there was a way to commit only specific chunks after the user selects them. For git, I think we can use git apply with a patch file, and there are many plugins which provide this feature for git (but none that I know of for mercurial).

I'm looking for something that exists in mercurial's public CLI interface, since they discourage using the python hg libraries (it's not considered a stable API).

spaceghost
  • 485
  • 2
  • 12
  • 2
    thg uses --partials to do this: hg commit --verbose --message=dsf --partials "cthg-patch-vt5ctp" -- somefile.txt doesn't appear to be documented, but given thg uses it I suspect it's safe to use. – Tom Nov 15 '21 at 22:19
  • 1
    @Tom: Apparently `--partials` [is a thg extension](https://aur.archlinux.org/packages/tortoisehg#comment-729127). – ecm Mar 20 '22 at 12:38
  • The only way that I know of is to pass filenames to `hg commit`, either plain files to include or `-X` files to exclude. However, this is only good for including or excluding whole files. – ecm Mar 20 '22 at 12:45
  • [This question](https://stackoverflow.com/questions/21608997/what-is-git-staging-and-why-does-hg-ostensibly-not-support-it) suggests that the `mq` extension can be used similarly to the `git` staging area. I have no experience in using it however. – ecm Mar 20 '22 at 13:41

0 Answers0