Merge pull request #339 from github/prepush

Make the pre-push hook check that git-lfs exists first
This commit is contained in:
Scott Barron 2015-05-28 11:56:07 -04:00
commit 5ebb953e01
2 changed files with 9 additions and 1 deletions

@ -17,10 +17,11 @@ var (
valueRegexp = regexp.MustCompile("\\Agit[\\-\\s]media")
NotInARepositoryError = errors.New("Not in a repository")
prePushHook = "#!/bin/sh\ngit lfs pre-push \"$@\""
prePushHook = "#!/bin/sh\ncommand -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository has been set up with Git LFS but Git LFS is not installed.\\n\"; exit 0; }\ngit lfs pre-push \"$@\""
prePushUpgrades = map[string]bool{
"#!/bin/sh\ngit lfs push --stdin $*": true,
"#!/bin/sh\ngit lfs push --stdin \"$@\"": true,
"#!/bin/sh\ngit lfs pre-push \"$@\"": true,
}
)

@ -8,6 +8,7 @@ begin_test "update"
set -e
pre_push_hook="#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository has been set up with Git LFS but Git LFS is not installed.\\n\"; exit 0; }
git lfs pre-push \"\$@\""
mkdir without-pre-push
@ -33,6 +34,12 @@ git lfs push --stdin \"\$@\"" > .git/hooks/pre-push
[ "Updated pre-push hook" = "$(git lfs update)" ]
[ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
# replace old hook 3
echo "#!/bin/sh
git lfs pre-push \"\$@\"" > .git/hooks/pre-push
[ "Updated pre-push hook" = "$(git lfs update)" ]
[ "$pre_push_hook" = "$(cat .git/hooks/pre-push)" ]
# don't replace unexpected hook
echo "test" > .git/hooks/pre-push
expected="Hook already exists: pre-push