| Norbert Thiebaud | f616441 | 2010-11-20 23:06:14 -0600 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | r= |
| 3 | b= |
| 4 | g="$(git rev-parse --git-dir 2>/dev/null)" |
| 5 | |
| 6 | if [ -n "$g" ]; then |
| 7 | if [ -d "$g/../.dotest" ] |
| 8 | then |
| 9 | if test -f "$g/../.dotest/rebasing" |
| 10 | then |
| 11 | r="|REBASE" |
| 12 | elif test -f "$g/../.dotest/applying" |
| 13 | then |
| 14 | r="|AM" |
| 15 | else |
| 16 | r="|AM/REBASE" |
| 17 | fi |
| 18 | b="$(git symbolic-ref HEAD 2>/dev/null)" |
| 19 | elif [ -f "$g/.dotest-merge/interactive" ] |
| 20 | then |
| 21 | r="|REBASE-i" |
| 22 | b="$(cat "$g/.dotest-merge/head-name")" |
| 23 | elif [ -d "$g/.dotest-merge" ] |
| 24 | then |
| 25 | r="|REBASE-m" |
| 26 | b="$(cat "$g/.dotest-merge/head-name")" |
| 27 | elif [ -f "$g/MERGE_HEAD" ] |
| 28 | then |
| 29 | r="|MERGING" |
| 30 | b="$(git symbolic-ref HEAD 2>/dev/null)" |
| 31 | else |
| 32 | if [ -f "$g/BISECT_LOG" ] |
| 33 | then |
| 34 | r="|BISECTING" |
| 35 | fi |
| 36 | if ! b="$(git symbolic-ref HEAD 2>/dev/null)" |
| 37 | then |
| 38 | if ! b="$(git describe --exact-match HEAD 2>/dev/null)" |
| 39 | then |
| 40 | b="$(cut -c1-7 "$g/HEAD")..." |
| 41 | fi |
| 42 | fi |
| 43 | fi |
| 44 | |
| 45 | if [ -n "$1" ]; then |
| 46 | printf "$1" "${b##refs/heads/}$r" |
| 47 | else |
| 48 | printf "%s" "${b##refs/heads/}$r" |
| 49 | fi |
| 50 | else |
| 51 | printf "not-in-git" |
| 52 | fi |