1

I'm trying to write a commit-msg script that calls a powershell script with the commit message passed in as a parameter.

So far I am able to execute the powershell script with parameters, but I cannot figure out how to access the commit message inside of commit-msg. Since the commit isn't completed yet, I cannot use the log. What other options are there?

Here is the code I have in commit-msg so far:

exec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command "& {C:/Windows/System32/WindowsPowerShell/git-pre-commit.ps1 '{the_git_commit_message}'}"
2
  • Can you clarify the flow of information you want (perhaps, giving all the scripts involved specific names, or giving an example of use)? It sounds to me like you could simply pass the parameter through into your other script. Commented Oct 19, 2011 at 15:48
  • I need the commit message to make it to the powershell script before a commit is completed with the ultimate goal of aborting the commit if the commit message does not meet certain criteria. Commented Oct 19, 2011 at 15:58

2 Answers 2

1

The argument for the commit-msg hook ($1) is the name of the file having the message. Pass the file (path) to the powershell script and add the content you want to this file and exit from the script.

Also, depending on what you are doing you may want to look at prepare-commit-msg hook

PS: Look at the commit-msg.sample file under .git/hooks to get some idea.

Sign up to request clarification or add additional context in comments.

2 Comments

As far as I can tell, that file does not contain the latest commit message. hook($1) gives me COMMIT_EDITMESSAGE, which does not help me.
@JacobHuggart - that is the file name that the commit message is stored as. You can open the file and read the entire commit message.
1

From Pro Git book:

After the entire commit process is completed, the post-commit hook runs. It doesn’t take any parameters, but you can easily get the last commit by running git log -1 HEAD. Generally, this script is used for notification or something similar.

If I understand you correctly you want the actual message and pass the contents of the commit message to the powershell script and not interested in modifying the message.

Read more about it here:

http://progit.org/book/ch7-3.html

Cheers

1 Comment

the link is not the best

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.