From 38dcfefff66da011a474fa95f96f71a8ae905a5b Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Mon, 9 Mar 2015 11:06:44 +0000 Subject: ensure remote_branch_name is fails quietly --- git-base.sh | 2 +- test-branches.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/git-base.sh b/git-base.sh index 000b184..94e9070 100755 --- a/git-base.sh +++ b/git-base.sh @@ -123,7 +123,7 @@ readable_branch_name() { remote_branch_name() { local localRef="$(git symbolic-ref -q HEAD 2>/dev/null)" - local remoteBranch="$(git for-each-ref --format='%(upstream:short)' refs/heads $localRef )" + local remoteBranch="$(git for-each-ref --format='%(upstream:short)' refs/heads $localRef 2>/dev/null)" if [[ -n $remoteBranch ]]; then echo $remoteBranch return 0 diff --git a/test-branches.sh b/test-branches.sh index 4ed7957..40c5a50 100755 --- a/test-branches.sh +++ b/test-branches.sh @@ -78,4 +78,25 @@ test_branch_name_returns_error() { rm_tmp } +test_remote_branch_name_quiet_when_not_in_repo() { + cd_to_tmp + + debug_output="$( + { + set -x + output="$( + remote_branch_name; + )" + set +x + } 2>&1 + echo "$output" + )" + + usages="$(echo "$debug_output" | grep 'fatal: ' | wc -l)" + + assertEquals " 0" "$usages" + + rm_tmp +} + . ./shunit/shunit2 -- cgit v1.2.3