From 2f505b0d5a021447f0f2fe3efc7f367e40be4d90 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 11 Aug 2023 10:37:16 -0400 Subject: [PATCH] fix(gittools): gittree wouldn't run in branchless repos gittree used to be `gittreeif @` on the theory that every git repo had @ or HEAD. But a git repo with no branches at all, not even main, has no HEAD. Now that we have repos used exclusively for issues, we have to deal with zero commits, zero branches. --- gittools.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gittools.sh b/gittools.sh index b6fd5505..12d4acb1 100644 --- a/gittools.sh +++ b/gittools.sh @@ -1,6 +1,6 @@ # Source this file to define some useful aliases for working with many git # repos at once. -# Originally from: +# Originally from: # https://github.com/nedbat/dot/blob/a517603c4969b017d5604418d05babc4a0f323f8/.rc.sh#L126 @@ -38,7 +38,9 @@ gittreeif() { fi find . -name .git -type d -prune | while read d; do local d=$(dirname "$d") - git -C "$d" rev-parse --verify -q "$test_branch" >& /dev/null || continue + if [[ "$test_branch" != "" ]]; then + git -C "$d" rev-parse --verify -q "$test_branch" >& /dev/null || continue + fi if [[ $show_dir == true ]]; then echo "---- $d ----" fi @@ -54,6 +56,6 @@ gittreeif() { } gittree() { - # @ is in every repo, so this runs on all repos - gittreeif @ "$@" + # Run a command on all git repos. + gittreeif "" "$@" }