I am making my own template that involves my a bit of custom git hooks. I opened the hooks folder, and everything was a .sample file which I know nothing about.
What I am doing is manipulating the commit-msg.sample file in my hooks folder, and I messed it up... My textbook stated: "We'll use the commit-msg hook as the example hook:"
#!/bin/sh
MSG_FILE="$1"
echo "\nHi from the template commit-msg hook" >> $MSG_FILE
I decided that I would manipulate the file manually, and my file commit-msg.sample file looks like this.
#!/bin/sh
MSG_FILE="$1"
"\nHi from the template commit-msg hook" >> $MSG_FILE
# a bunch of comments....
MSG_FILE="$1"
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo >&2 \nHi from the template commit-msg hook >> $MSG_FILE
exit 1
}
However, when I do git log -1, I end up with the default and no "\nHi from the template commit-msg hook". I want it so that whenever I do git log -1, it also displays that message.
What am I doing wrong here? Any explanation would be great.
Here is my reproductible example:
- Create a
.git_templatedirectory - Add a hooks and info folder
- Copy and paste all the files from hooks and info folders in the default directory (usually the
/usr/share/git-core/templates) and put them into the.git_template's hooks and and info directories respectively - Now in the
.git_template/hooksyou should find acommit-msg.sample. - below
#!/bin/sh, delete everything else and write down
echo "\nHi from the template commit-msg hook" >> $MSG_FILE
- In the terminal, do the
chmod +x commit-msg.sample - Using the absolute file path, do the following command.
git config --global init.templatedir [ABSOLUTE PATH]/.git_template
- In a completely new folder, initialize a git repository. Add anything say index.js then do
git add *thengit commit -m "my message" - Now do
git log -1 - Now the expected output is "my message \nHi from the template commit-msg hook". Basically it's supposed to be the git commit message plus the hook's message. However, I only get the git commit message which is "my message".
If there's a step that I did wrong, please let me know.