From 9f37443474de3de63f4484089f24b25ecf234f38 Mon Sep 17 00:00:00 2001 From: MarMar Labs Date: Fri, 21 Aug 2026 07:50:51 -0500 Subject: [PATCH] fix(show_env): keep git errors out of the environment report (#18597) ### Summary `show_env.sh` exists to produce a clean environment report to paste into an issue. Run outside a work tree it printed a raw git error into the middle of it. --- show_env.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/show_env.sh b/show_env.sh index ffe4016893..085596cf31 100644 --- a/show_env.sh +++ b/show_env.sh @@ -17,10 +17,21 @@ get_distro_info() { # get Git repository name git_repo_name='' -if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then - git_repo_name=$(basename "$(git rev-parse --show-toplevel)") - if [ $? -ne 0 ]; then - git_repo_name="(Can't get repo name)" +if git_toplevel=$(git rev-parse --show-toplevel 2>/dev/null); then + git_repo_name=$(basename "$git_toplevel") +elif git_dir=$(git rev-parse --absolute-git-dir 2>/dev/null); then + # Inside .git, or in a bare repo: there is no work tree to name, but this is + # still a repository. Ask git whether it is bare rather than reading the + # path, since a bare repo may itself be called ".git". A bare repository + # names itself; otherwise the git directory's parent is the repository. + if [ "$(git rev-parse --is-bare-repository 2>/dev/null)" = "true" ]; then + git_repo_name=$(basename "$git_dir") + else + # A linked worktree's git dir lives under .git/worktrees, so the main + # repository is found through the common dir. That is reported relative + # to the git dir (plain "." inside .git), hence resolving it here. + git_common=$(cd "$git_dir" && cd "$(git rev-parse --git-common-dir)" && pwd) + git_repo_name=$(basename "$(dirname "$git_common")") fi else git_repo_name="It is NOT a Git repo" @@ -47,7 +58,7 @@ python_version=$(python3 --version 2>&1 || python --version 2>&1 || echo "Python echo "Current Repository: $git_repo_name" # get Commit ID -git_version=$(git log -1 --pretty=format:'%h') +git_version=$(git log -1 --pretty=format:'%h' 2>/dev/null) if [ -z "$git_version" ]; then echo "Commit Id: The current directory is not a Git repository, or the Git command is not installed."