diff options
| author | Michael Allen <michael@michaelallen.io> | 2015-02-18 09:12:06 +0000 | 
|---|---|---|
| committer | Michael Allen <michael@michaelallen.io> | 2015-02-18 11:53:36 +0000 | 
| commit | 937a5452e2e7cebe195855e7360331345bb242a2 (patch) | |
| tree | a9cfb3bb6c6d33d51eeb02d311843f276cda374a /test | |
| parent | 01538d46bac4d2607ad01d04548085f6918ba4d0 (diff) | |
| download | git-sonar-937a5452e2e7cebe195855e7360331345bb242a2.tar.gz git-sonar-937a5452e2e7cebe195855e7360331345bb242a2.zip | |
handle detached heads cleanly
Diffstat (limited to '')
| -rwxr-xr-x | test-branches.sh | 44 | 
1 files changed, 43 insertions, 1 deletions
| diff --git a/test-branches.sh b/test-branches.sh index ddf442c..4ed7957 100755 --- a/test-branches.sh +++ b/test-branches.sh @@ -12,7 +12,7 @@ cd_to_tmp() {  rm_tmp() {    cd $scriptDir -  rm -r "$tmpfile" +  rm -rf /tmp/git-prompt-tests*  }  test_branch_name_in_repo() { @@ -36,4 +36,46 @@ test_branch_name_not_in_repo() {    rm_tmp  } +test_detached_from_branch() { +  cd_to_tmp +  git init --quiet +  assertEquals "master" "$(branch_name)" + +  touch README +  git add . +  git commit -m "initial commit" --quiet + +  touch foo +  git add . +  git commit -m "foo" --quiet + +  git checkout --quiet HEAD^ >/dev/null +  sha="$(commit_short_sha)" + +  assertNotEquals "master" "$(branch_name)" +  assertEquals "$sha" "$(branch_ref)" +  assertEquals "detached@$sha" "$(readable_branch_name)" + +  rm_tmp +} + +test_branch_name_returns_error() { +  cd_to_tmp +  git init --quiet + +  touch README +  git add . +  git commit -m "initial commit" --quiet + +  touch foo +  git add . +  git commit -m "foo" --quiet + +  git checkout --quiet HEAD^ >/dev/null + +  retcode="$(branch_name; echo $?)" +  assertEquals "1" "$retcode" +  rm_tmp +} +  . ./shunit/shunit2 | 
