From 113be25cfafed34a1e8d45bdf5a2661b102a4da6 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 11 Mar 2017 00:03:55 -0800 Subject: [PATCH] tg status: behave reasonably in a bare repository Although there's no working tree in a bare repository, the information for HEAD (and even conceivably an upstream) can be shown without issue. Make it so and just automatically omit the working tree information when `tg status` is run in a bare repository. Signed-off-by: Kyle J. McKay --- t/t1050-status.sh | 13 ++++++++++++- tg.sh | 11 ++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/t/t1050-status.sh b/t/t1050-status.sh index c7264a5..aeeeb5b 100755 --- a/t/t1050-status.sh +++ b/t/t1050-status.sh @@ -7,14 +7,18 @@ Make sure tg status detects everything it should. . ./test-lib.sh -test_plan 15 +test_plan 17 unborn='HEAD -> master [unborn] working directory is clean' +bareub='HEAD -> master [unborn]' + born='HEAD -> master [7cfc564] working directory is clean' +bare='HEAD -> master [7cfc564]' + headborn='HEAD -> master [7cfc564] ' allfixed=' @@ -44,6 +48,9 @@ working directory is clean' test_expect_success 'tg status unborn' ' test "$unborn" = "$(tg status)" ' +test_expect_success 'tg status unborn (bare)' ' + test "$bareub" = "$(tg -C .git -c core.bare=true status 2>&1)" +' test_expect_success 'tg status unborn untracked' ' >not-ignored && @@ -58,6 +65,10 @@ test_expect_success LASTOK 'tg status born' ' test "$born" = "$(tg status)" ' +test_expect_success LASTOK 'tg status born (bare)' ' + test "$bare" = "$(tg -C .git -c core.bare=true status 2>&1)" +' + test_expect_success 'tg status born untracked' ' >not-ignored && test "$born$unignored" = "$(tg status)" && diff --git a/tg.sh b/tg.sh index 548d2a8..77ea398 100644 --- a/tg.sh +++ b/tg.sh @@ -1249,12 +1249,13 @@ do_status() fi fi if [ -z "$git_state" ]; then - ccnt="$(( $(git status --porcelain -uno | wc -l) ))" + gsp="$(git status --porcelain 2>/dev/null)" || return 0 # bare repository + gspcnt=0 + [ -z "$gsp" ] || + gspcnt="$(( $(printf '%s\n' "$gsp" | LC_ALL=C sed -n '/^??/!p' | wc -l) ))" untr= - if [ "$ccnt" -eq 0 ]; then - if git status --porcelain | grep -q '^[?]'; then - untr="; non-ignored, untracked files present" - fi + if [ "$gspcnt" -eq 0 ]; then + [ -z "$gsp" ] || untr="; non-ignored, untracked files present" echo "${pfx}working directory is clean$untr" [ -n "$tg_state" ] || do_status_result=0 else -- 2.11.4.GIT