I have a git post-checkout hook that automatically re-compiles my Visual Studio project whenever I checkout to a different commit. This works great, but I have noticed that the hook also executes when I do a revert in TortoiseGit, both from the log-window and from the commit window (I right-click the file I want to revert and then click "Revert" in the pop-up menu). Is there a way to prevent this from happening?
Asked
Active
Viewed 123 times
1 Answers
1
According to post-checkout,
The hook is given three parameters: the ref of the previous HEAD, the ref of the new HEAD (which may or may not have changed), and a flag indicating whether the checkout was a branch checkout (changing branches, flag=1) or a file checkout (retrieving a file from the index, flag=0).
You can test the 3rd parameter. If it's 0, do not compile. For example in Bash,
#!/bin/bash
flag=$3
if [[ "$flag" -eq 0 ]];then
exit 0
fi
In Python,
#!/usr/bin/env python
import sys
flag = sys.argv[3]
if flag == '0':
sys.exit(0)

ElpieKay
- 27,194
- 6
- 32
- 53