-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from greg0ire/make
Add support for make
- Loading branch information
Showing
7 changed files
with
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Description | ||
|
||
Runs one or several make targets on pre-commit, or on pre-push, or both. | ||
|
||
# Activation | ||
|
||
```sh | ||
git config --add hooks.enabled-plugins make | ||
``` | ||
|
||
# Configuration | ||
|
||
By default, the `test` target will be run. To change the target: | ||
|
||
```sh | ||
git config hooks.make.target "my_target my_other_target" | ||
``` | ||
|
||
By default, `make` is only run on pre-push, but pre-commit is also supported. | ||
To change this, you can specify a list of hooks to run `make` on: | ||
|
||
```sh | ||
git config hooks.make.on "pre-commit pre-push" | ||
``` |
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,10 @@ | ||
#!/bin/bash | ||
# shellcheck source=../git_config_wrapper.sh | ||
. "$GIT_DIR/hooks/git_config_wrapper.sh" | ||
|
||
get_hook_config make on hooks optional "pre-push" | ||
|
||
if echo "$hooks"|grep --quiet pre-commit > /dev/null | ||
then | ||
. "$GIT_DIR/hooks/make/run-make" | ||
fi |
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,11 @@ | ||
#!/bin/bash | ||
# shellcheck source=../git_config_wrapper.sh | ||
gitDir=$(git rev-parse --git-dir) | ||
. "$gitDir/hooks/git_config_wrapper.sh" | ||
|
||
get_hook_config make on hooks optional "pre-push" | ||
|
||
if echo "$hooks"|grep --quiet pre-push > /dev/null | ||
then | ||
. "$gitDir/hooks/make/run-make" | ||
fi |
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,8 @@ | ||
#!/bin/bash | ||
# shellcheck source=../git_config_wrapper.sh | ||
gitDir=$(git rev-parse --git-dir) | ||
. "$gitDir/hooks/git_config_wrapper.sh" | ||
|
||
get_hook_config make target target optional test | ||
|
||
make --directory="$(git rev-parse --show-toplevel)" $target |
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,57 @@ | ||
#!/bin/sh | ||
|
||
testExitsWithCodeGreaterWhenMakeFails() | ||
{ | ||
initRepo | ||
cat > Makefile <<MAKEFILE | ||
my_target: | ||
false | ||
MAKEFILE | ||
git add Makefile | ||
git commit --message "Let's commit the Makefile" 1> /dev/null 2> "${stderrF}" | ||
rtrn=$? | ||
assertEquals "Make failure was not detected" 1 $rtrn | ||
} | ||
|
||
testItSupportsSeveralTargets() | ||
{ | ||
initRepo | ||
cat << MAKEFILE > Makefile | ||
my_target: | ||
echo "my_target" >> foo/result | ||
my_other_target: | ||
echo "my_other_target" >> foo/result | ||
MAKEFILE | ||
git config hooks.make.target "my_target my_other_target" | ||
git add Makefile | ||
mkdir foo | ||
cd foo || exit 1 | ||
git commit --message "Let's commit the Makefile" 1> /dev/null 2> "${stderrF}" | ||
rtrn=$? | ||
assertEquals "Make ran successfully" 0 $rtrn | ||
assertTrue 'First target was not run' "grep my_target result" | ||
assertTrue 'Second target was not run' "grep my_other_target result" | ||
} | ||
|
||
initRepo() | ||
{ | ||
cd "$testRepo" || exit 1 | ||
git init --quiet . | ||
git config hooks.enabled-plugins make | ||
git config hooks.make.target my_target | ||
git config hooks.make.on "pre-commit pre-push" | ||
} | ||
|
||
oneTimeSetUp() | ||
{ | ||
outputDir="${SHUNIT_TMPDIR}/output" | ||
mkdir "${outputDir}" | ||
stderrF="${outputDir}/stderr" | ||
|
||
testRepo=$SHUNIT_TMPDIR/test_repo | ||
mkdir --parents "$testRepo" | ||
} | ||
|
||
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 | ||
. "$(which shunit2)" |