I need to graft a large number (thousands) of small changesets from branch A to branch B - but need to alter the commit message in the process.
The message change needs to look roughly like this:
"Ref XXX: Fixed foo and bar" -> "GRAFT: Ref YYY: Fixed foo and bar".
In other words, I need to prepend "GRAFT:" and change a reference number. If I can't make these replacements directly with Mercurial, I could create the new commit messages all in advance then make a script to apply each new message during its respective graft. Happily, Mercurial allows editing commit messages during grafting, with the -e argument:
https://www.mercurial-scm.org/repo/hg/help/graft
The problem is that this pops up a text editor for each changeset for me to make the change manually. There doesn't seem to be a way to amend the message in a programmatic way, or just to provide an entirely new message, at the comment line. Given the size of operation, using the editor each time isn't plausible.
My last option would be to use the text editor with some sort of AutoIt/Macro script to enter the right things in the places at the right times - but the thought of needing to resort to this is frankly making me feel a bit ill.
Save me from this ugly fate.
Thanks in advance.
A possible workaround is to specify the use of a shell script in lieu of an editor. For example:
#!/bin/sh
sed -e '1,1s/^/GRAFT: /' -i "$1"
We're making use of the fact that with -i
, sed
will do an in-place edit. Don't forget to make the shell script executable. Then you can run
hg graft --config ui.editor=/path/to/prepend-graft.sh -e -r <revision>
where /path/to/prepend-graft.sh
is the path of the aforementioned shell script.
Changing a number may require code that's more complex than a sed script, but would follow the same approach.