Thoughts on adding another hook to git
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
I'd like to be able to modify the commit message before it ends up in the $EDITOR. This is a fairly trivial thing to implement:
Call ${GIT_DIR}/hooks/pre-editor on COMMIT_MESSAGE before opening it in $EDITOR.
My question to you all is should I set it up so that the hook only opens when the $EDITOR is actually being called? (really easy)
Or, do I set it up so that the hook always happens. In which case it's similar to the commit-msg hook already, just happens before the message instead of after.
Thanks,
- --
David Kowis
ISO Team Lead - www.sourcemage.org
Source Mage GNU/Linux
Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.
- Robert Heinlein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iQGVAwUBRI2yAMnf+vRw63ObAQpNSgv+OCXYSDlW96K9M5QZvSaEbdZOGorYZg5Y RSh9WUXS2ribYRr1TbplD0Fp4vGnG8CB6qvr2QF8vP3tbEMjnwk4LobeWaUtK2Kn Hja3TgIUPWkzHMLleToe5o99r8v/6LFf9rkBxvFw3TMkuxsFS/lFlxy1eRa43rvd Skod2cA7RWus1IFJcbDKNonjhJkVkHylSMjT8iVQDbgY0hg7PEy2ZW3XB0MJJRZC lLsDDIJ4msPCXSx/lDRGaJj+m7IrvUgnEDzkX0jTT8DeZqnlC8nRM/2dOS72b/5w gIBYu49DvTL8ynod2mmYTyBynfRpVxPjxnXbubn/M+N+0WCTXIUTPCbyW2MOscjA pFe6/S1qKaTqc06VBDabYxdvGrHG6v+KkaJhu2XoLOHWVoBblobBBNrpIkA6GNqz H7JHNJDF+JbshlW2aU2HazDINRfD/AfrJmDx4Xn91qAKiegyO3wRA1rM6a0LEpun zg3haF3l0rfBEdFpz21gNQbYxNHaRkwg
=Rxm/
-----END PGP SIGNATURE-----
Quoted 4 lines · David Kowis
I'd like to be able to modify the commit message before it ends up in the $EDITOR. This is a fairly trivial thing to implement:
Call ${GIT_DIR}/hooks/pre-editor onCOMMIT_MESSAGEbefore opening it in $EDITOR.
Three random thoughts.
- pre-editor is too generic a name because before making a commit is not the only place we give you $EDITOR (both am and tag do EDITOR thing IIRC). So the hook name must be more specific to the commit codepath (otherwise your pre-editor hook needs to be able to tell which codepath called it).
- git-commit gives you EDITOR when you are making a merge, and you would probably want to keep the default merge commit message without the prefixed directory thing. You probably do not want to do this while doing --amend either.
- it might make sense to have a "commit template" that is used when making a non-merge commit afresh (i.e. without -F, -m, -c or -C to specify messages), instead of a hook script.
Quoted 2 lines · David Kowis
I'd like to be able to modify the commit message before it ends up in the $EDITOR.
Can't you define $EDITOR to point to some script which modifies the file as you wish then calls the real editor on it ?
Yakov
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Quoted 8 lines · Yakov Lerner
Quoted 2 lines · David Kowis
I'd like to be able to modify the commit message before it ends up in the $EDITOR.
Can't you define $EDITOR to point to some script which modifies the file as you wish then calls the real editor on it ?
I could, but then anything else that uses $EDITOR would also be affected in the same way... Which would produce interesting results.
- --
David Kowis
ISO Team Lead - www.sourcemage.org
Source Mage GNU/Linux
Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.
- Robert Heinlein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iQGVAwUBRI28K8nf+vRw63ObAQoKPgv9EvwbDkGmct7IZGFMydea+HlIMWR+Jyla WHYnCN353Hw+WbOIvnTvlJrI1R+zSYIu2tDhZ2P/2czyWyja8HQHjGhTXbBInILX T4ODPwZ55od4uDi1arnHgRpJwhLeGIU+1Wxc8k70tszWj2gb6sIGMHcK9LhzZ+Sf lEY6iGF74TE3gyQsj78smxL/COvNjzoCWY4AieIVxtu7b1shb7lZXbnkfcKhs82L 0bdmHKri7999nxgWnmdyaDi9RuYOKinc/YhrKDrvY2GB5c8BQHgpFMDR/17oTREL PTmAJwFs8dAAalGmPAajZY1gXrqo/lVb4JPK4b2QboEC8SGpFwcq4jtHCr/s2mQd uNINnZ62+dxgRxk9koW2QZeh7hPB8rFcIufUhUC19P0+UWv5TDuKie/mR1U6uZNN BfTIj/1AI5+l9kCJS+om9o8P1m2wPW4MsP2XaqatInUz9YXn14zrjcKTZnCuIMvw mqrBlfI7L2KEsoL4ywJsb4ATVz7M6G0I
=IFOu
-----END PGP SIGNATURE-----
Quoted 8 lines · David Kowis
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512Quoted 4 lines · Yakov Lerner
Quoted 2 lines · David Kowis
I'd like to be able to modify the commit message before it ends up in the $EDITOR.
Quoted 7 lines
Quoted 4 lines
Can't you define $EDITOR to point to some script which modifies the file as you wish then calls the real editor on it ?
I could, but then anything else that uses $EDITOR would also be affected in the same way... Which would produce interesting results.
git-commit sure creates those temp files with specific naming in specific dir. You could check for that in EDITOR script. In the script, you could even check the name of the parent process.
Yakov
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Quoted 14 lines · Yakov Lerner
Quoted 13 lines · David Kowis
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512Quoted 8 lines · Yakov Lerner
Quoted 2 lines · David Kowis
I'd like to be able to modify the commit message before it ends up in the $EDITOR.
Can't you define $EDITOR to point to some script which modifies the file as you wish then calls the real editor on it ?
Quoted 8 lines
Quoted 2 lines
I could, but then anything else that uses $EDITOR would also be affected in the same way... Which would produce interesting results.
git-commit sure creates those temp files with specific naming in specific dir. You could check for that in EDITOR script. In the script, you could even check the name of the parent process.
This is true. However, I'd be running that script every time something invoked $EDITOR. And some people may not like that solution. I'm thinking that more than just I will like to use this pre-edit hook. Especially in the distro I'm helping develop.
- --
David Kowis
ISO Team Lead - www.sourcemage.org
Source Mage GNU/Linux
Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.
- Robert Heinlein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iQGVAwUBRI2+68nf+vRw63ObAQo6Kwv/bmLf8f54lm7sXekww8olFwT3SkE8orHk BozzIyW8foz+FLtVbjQQbbGw1RgLrL5zPn+De+BM3LwXabhqnsVca2KpQVMkLaqx aJwjn2JvL6ujG3ponuCCPTk5VhzU0C/Su15eIMa86O2EFu6Y0HBhw/hOnyEWJiYa tOxPETizJHD1YbneoTJmu+tQFaKbjAD/3tUMDkQBp9h1QkbZHD5LQUjozepLZplY PfOvZIP9fT6GDsK5SuweGrYZHjzuV0RlrwN191No3FsJMMX7+PQ85MBvj1p/xJG7 VO+z33+IYPascpm/3NdpjdtKAh72+rfW5OUd8FN1ISwPtY9dJeh5zaaCTB+oEqL4 56pchLL33SFphOO5//YwHcwgX61tPK0stsVpjfdQHEjz8BHNSoBhZw3lw/AvO+63 UhiA3rjiIFrYe9piJHlX+IxoNo5OaLJNO2KjV9k15+0FxSzbKPn3Pt2Ee90ootEn 8NzHFVoyOWnt5mPM+jQr4DsPgrikeUaO
=3hwD
-----END PGP SIGNATURE-----
Quoted 11 lines · David Kowis
Quoted 4 lines · Yakov Lerner
git-commit sure creates those temp files with specific naming in specific dir. You could check for that in EDITOR script. In the script, you could even check the name of the parent process.
This is true. However, I'd be running that script every time something invoked $EDITOR. And some people may not like that solution. I'm thinking that more than just I will like to use this pre-edit hook. Especially in the distro I'm helping develop.
Perhaps you could tell us what editor you are using. That way we may provide additional solutions.
nikolai
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Quoted 8 lines · Nikolai Weibull
Quoted 6 lines · David Kowis
Quoted 4 lines · Yakov Lerner
git-commit sure creates those temp files with specific naming in specific dir. You could check for that in EDITOR script. In the script, you could even check the name of the parent process.
Quoted 8 lines
Quoted 4 lines
This is true. However, I'd be running that script every time something invoked $EDITOR. And some people may not like that solution. I'm thinking that more than just I will like to use this pre-edit hook. Especially in the distro I'm helping develop.
Perhaps you could tell us what editor you are using. That way we may provide additional solutions.
I'm using vim. But that's irrelevant with what I'm trying to do.
Perhaps I need to explain more:
In SourceMage, we have a collection of scripts, the grimoire, that contain the little bits of instructions on how to build and install all the software. 99% of the time most commits are based in one directory. For example:
I just updated the abook spell (A spell is that collection of instructions I mentioned earlier.)
I modified two files. DETAILS and HISTORY.
DETAILS contains the version information, and a source hash to verify downloads (and a bit of other stuff, but it's not important). HISTORY is just a changelog. Now I do git commit .
I get:
1 # Explicit paths specified without -i nor -o; assuming --only paths... 2 #
3 # Updated but not checked in:
4 # (will commit)
5 #
6 # modified: mail/abook/DETAILS
7 # modified: mail/abook/HISTORY
What I'd like to be able to do is have that "abook" directory name automatically added to the top of my commit message before it gets into the editor. I can do this with a script (echo ${PWD##*/}) but it'd need to be a hook before the editor shows up.
1 abook:
2 # Explicit paths specified without -i nor -o; assuming --only paths... 3 #
4 # Updated but not checked in:
5 # (will commit)
6 #
7 # modified: mail/abook/DETAILS
8 # modified: mail/abook/HISTORY
It helps in the short log (git log) for describing for which spell the log refers. Although it could be done with an EDITOR script I don't think that's the best solution. It's certainly not a good solution to give out to a lot of people. Most of the changes to our grimoire are like this one, so this would be extremely useful to us.
Hope that clears things up a bit,
- --
David Kowis
ISO Team Lead - www.sourcemage.org
Source Mage GNU/Linux
Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.
- Robert Heinlein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iQGVAwUBRI63tsnf+vRw63ObAQqvqAv/QkyEi4/wIDo+sQGMPkXhj/e7yMDXbVLm XYaVhlxOG3rXfaEu6ecdjm8b6h4UYCMFnhYKUiDqD42LlEdofCIOecGULyP5Nx9q JAL8BaZpq4MwRQt4HiX9oLQBTIW2ZcD9Fg5ZqFUL3QWFbjednbEl+M8/41JGFL4s XpvIcKHfAy90qdG5QrgsHdQTAS6JG+9mFmyi4d0wlDWBh4WoutfEfL/nwbH79d2B Udq6j/SIy0dmsbjNmzJnPYn5IVrFYGez4y5bW7LDpO5ddf4027iz9mNb8hd0wCzL akh1f4xQQ178iaFz4y60TTmNavxswRmdoKTghRKet0MXTtBTUXe0TUJ5vNOtKODz 5MWu9M5/olCcLqlb7L6wnvqJ9HnJTvAEAUQpvKztQcC2Uy2XkpznW3XmeEK50CLU VQjxSzubUfXDxkf/hS1nY3WKL3UuQoGWVDmL2Maxno+Kwb3YoyW5+etvYvfoqNT7 Vi7bpiX6fPVF/r6ogATzqla2EFLsta1f
=m3vG
-----END PGP SIGNATURE-----
Quoted 10 lines · David Kowis
I'm using vim.
1 # Explicit paths specified without -i nor -o; assuming --only paths... 2 #
3 # Updated but not checked in:
4 # (will commit)
5 #
6 # modified: mail/abook/DETAILS
7 # modified: mail/abook/HISTORY
Quoted 4 lines
What I'd like to be able to do is have that "abook" directory name automatically added to the top of my commit message before it gets into the editor. I can do this with a script (echo ${PWD##*/}) but it'd need to be a hook before the editor shows up.
autocmd BufRead .git/COMMIT_MSG call setline(1, expand('%:p:h:h:t'))
But that will of course do that for all commit-messages, so your point is still valid.
nikolai