-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental support for git commit-msg hook
Users can now install a git commit-msg hook using the --install-hook commandline flag. This is still experimental and missing some important features (uninstall, appending to existing hook, restoring incorrect commit message).
- Loading branch information
1 parent
5b25f4d
commit 3ab56fc
Showing
5 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import shutil | ||
import stat | ||
import sys | ||
import os | ||
|
||
COMMIT_MSG_HOOK_SRC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "hooks/commit-msg") | ||
COMMIT_MSG_HOOK_DST_PATH = os.path.abspath(".git/hooks/commit-msg") | ||
|
||
|
||
class GitHookInstaller(object): | ||
@staticmethod | ||
def install_commit_msg_hook(): | ||
# assert that current directory is a git repository | ||
if not os.path.isdir(".git/hooks"): | ||
sys.stderr.write("The current directory is not a git repository\n") | ||
exit(1) | ||
if os.path.exists(COMMIT_MSG_HOOK_DST_PATH): | ||
sys.stderr.write( | ||
"There is already a commit-msg hook file present in {}. \n".format(COMMIT_MSG_HOOK_DST_PATH) + | ||
"gitlint currently does not support appending to an existing commit-msg file.\n") | ||
exit(1) | ||
|
||
# copy hook file | ||
shutil.copy(COMMIT_MSG_HOOK_SRC_PATH, COMMIT_MSG_HOOK_DST_PATH) | ||
# make hook executable | ||
st = os.stat(COMMIT_MSG_HOOK_DST_PATH) | ||
os.chmod(COMMIT_MSG_HOOK_DST_PATH, st.st_mode | stat.S_IEXEC) | ||
|
||
# declare victory :-) | ||
sys.stdout.write("Successfully installed gitlint commit-msg hook in {0}\n".format(COMMIT_MSG_HOOK_DST_PATH)) | ||
exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
### gitlint commit-msg hook start ### | ||
|
||
cat "$1" | gitlint | ||
gitlint_exit_code=$? | ||
|
||
if [ $gitlint_exit_code -gt 0 ]; then | ||
echo "----------------------" | ||
echo "Your commit message: " | ||
echo "----------------------" | ||
cat "$1" | grep -v '^#' | ||
else | ||
echo "gitlint: OK" | ||
fi | ||
|
||
exit $gitlint_exit_code | ||
|
||
### gitlint commit-msg hook end ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters