From 417486780209cd5d57ad876c8a2942de5a7a1750 Mon Sep 17 00:00:00 2001 From: rick Date: Tue, 8 Sep 2015 10:20:52 -0600 Subject: [PATCH] test the exit code of the commands --- commands/command_update.go | 8 ++++++-- test/test-checkout.sh | 7 ++++++- test/test-fetch.sh | 7 ++++++- test/test-fsck.sh | 7 ++++++- test/test-ls-files.sh | 7 ++++++- test/test-pull.sh | 7 ++++++- test/test-status.sh | 7 ++++++- test/test-update.sh | 15 ++++++++++----- 8 files changed, 52 insertions(+), 13 deletions(-) diff --git a/commands/command_update.go b/commands/command_update.go index a2212bda..7fda63f0 100644 --- a/commands/command_update.go +++ b/commands/command_update.go @@ -1,6 +1,7 @@ package commands import ( + "os" "regexp" "github.com/github/git-lfs/git" @@ -22,8 +23,11 @@ var ( // .git/lfs. func updateCommand(cmd *cobra.Command, args []string) { if err := lfs.InstallHooks(updateForce); err != nil { - Error(err.Error()) - if !lfs.IsInvalidRepoError(err) { + if lfs.IsInvalidRepoError(err) { + Print(err.Error()) + os.Exit(128) + } else { + Error(err.Error()) Print("Run `git lfs update --force` to overwrite this hook.") } } else { diff --git a/test/test-checkout.sh b/test/test-checkout.sh index 6596f63a..5983afe6 100755 --- a/test/test-checkout.sh +++ b/test/test-checkout.sh @@ -106,7 +106,12 @@ end_test begin_test "checkout: outside git repository" ( + set +e + git lfs checkout 2>&1 > checkout.log + res=$? + set -e - git lfs checkout | grep "Not in a git repository" + [ "$res" = "128" ] + grep "Not in a git repository" checkout.log ) end_test diff --git a/test/test-fetch.sh b/test/test-fetch.sh index ad7d053d..c7605428 100755 --- a/test/test-fetch.sh +++ b/test/test-fetch.sh @@ -391,7 +391,12 @@ end_test begin_test "fetch: outside git repository" ( + set +e + git lfs fetch 2>&1 > fetch.log + res=$? + set -e - git lfs fetch | grep "Not in a git repository" + [ "$res" = "128" ] + grep "Not in a git repository" fetch.log ) end_test diff --git a/test/test-fsck.sh b/test/test-fsck.sh index 76973f6d..2d65c1d5 100755 --- a/test/test-fsck.sh +++ b/test/test-fsck.sh @@ -105,7 +105,12 @@ end_test begin_test "fsck: outside git repository" ( + set +e + git lfs fsck 2>&1 > fsck.log + res=$? + set -e - git lfs fsck | grep "Not in a git repository" + [ "$res" = "128" ] + grep "Not in a git repository" fsck.log ) end_test diff --git a/test/test-ls-files.sh b/test/test-ls-files.sh index 911fc6a5..0c65d0d0 100755 --- a/test/test-ls-files.sh +++ b/test/test-ls-files.sh @@ -29,7 +29,12 @@ end_test begin_test "ls-files: outside git repository" ( + set +e + git lfs ls-files 2>&1 > ls-files.log + res=$? + set -e - git lfs ls-files | grep "Not in a git repository" + [ "$res" = "128" ] + grep "Not in a git repository" ls-files.log ) end_test diff --git a/test/test-pull.sh b/test/test-pull.sh index 49374335..cd35dc40 100755 --- a/test/test-pull.sh +++ b/test/test-pull.sh @@ -98,7 +98,12 @@ end_test begin_test "pull: outside git repository" ( + set +e + git lfs pull 2>&1 > pull.log + res=$? + set -e - git lfs pull | grep "Not in a git repository" + [ "$res" = "128" ] + grep "Not in a git repository" pull.log ) end_test diff --git a/test/test-status.sh b/test/test-status.sh index f764177b..57fd4dc9 100755 --- a/test/test-status.sh +++ b/test/test-status.sh @@ -70,7 +70,12 @@ end_test begin_test "status: outside git repository" ( + set +e + git lfs status 2>&1 > status.log + res=$? + set -e - git lfs status | grep "Not in a git repository" + [ "$res" = "128" ] + grep "Not in a git repository" status.log ) end_test diff --git a/test/test-update.sh b/test/test-update.sh index 827db37e..3f3fc0b1 100755 --- a/test/test-update.sh +++ b/test/test-update.sh @@ -96,11 +96,16 @@ end_test begin_test "update: outside git repository" ( + set +e + git lfs update 2>&1 > check.log + res=$? + overwrite="$(grep "overwrite" check.log)" + set -e - git lfs update 2>&1 | tee update.log - grep "Not in a git repository" update.log - if [ "$(grep "overwrite" update.log)" ]; then - exit 1 - fi + echo "actual:" + cat check.log + [ "$res" = "128" ] + [ -z "$overwrite" ] + grep "Not in a git repository" check.log ) end_test