diff --git a/lfs/setup.go b/lfs/setup.go index 1e4d7b2a..e3c9a243 100644 --- a/lfs/setup.go +++ b/lfs/setup.go @@ -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, } ) diff --git a/test/test-update.sh b/test/test-update.sh index 28a58538..9cc7a99b 100755 --- a/test/test-update.sh +++ b/test/test-update.sh @@ -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