`git rev-parse --is-inside-work-tree` does not handle bare Git repositories correctly
ido123net opened this issue · comments
The current implementation of the prompt_git()
function does not handle bare Git repositories correctly. When the function checks if the current directory is inside a Git repository using the command git rev-parse --is-inside-work-tree
, it expects a return code of 0 and a corresponding output of "true" to indicate that the current directory is in a Git repository.
However, in the case of a bare Git repository, the command git rev-parse --is-inside-work-tree
returns a return code of 0, but the output is "false". This leads to incorrect behavior in the function, as it does not properly handle bare repositories and does not return as expected.
Steps to Reproduce:
- Create a bare Git repository using
git init --bare
. - Execute the
prompt_git()
function within the bare repository.
Actual Behavior:
The prompt_git()
function does not handle bare Git repositories correctly.
leading to fatal errors after. from git diff-files --quiet --ignore-submodules --
and git ls-files --others --exclude-standard
.
Proposed Solution:
- Check the repository type using
git rev-parse --is-bare-repository
command or another suitable method, and return early if it detects a bare repository. - Check if the output of
git rev-parse --is-inside-work-tree
isfalse
.
Additional Information:
Operating System: Linux
Git version: 2.37.3
Shell environment: Bash