;bin: git: make ensure_git more robust

Instead of manually checking for a .git directory, ask git to check whether
or not we are in a work tree using 'git rev-parse --is-inside-work-tree'.
This takes care of things like being in a subdirectory of a work tree, or
someone having GIT_DIR pointing somewhere other than .git, etc.
This commit is contained in:
Lars Kellogg-Stedman 2025-01-02 13:45:23 -05:00 committed by Simon Michael
parent 51e7ebae3d
commit d447d708f6

View File

@ -62,9 +62,8 @@ EOF
fi
}
# TODO: also look in parent directories
ensure_git_repo() {
if [[ ! -d "$DIR/.git" ]]; then
if [[ $($GIT -C "$DIR" rev-parse --is-inside-work-tree 2> /dev/null) != true ]]; then
$GIT init "$DIR"
echo "Created git repo in $DIR"
fi