mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
* fix(is-git-repo): recognize bare repositories is_git_repo() used `git rev-parse --show-toplevel` to detect whether the current directory is inside a git repository. --show-toplevel fails for bare repositories since they have no working tree, so every command that relies on this shared helper (e.g. `git browse`) reports "Not a git repo!" when run from inside a bare repo, even though it plainly is one. Switch to `git rev-parse --git-dir`, which succeeds for both normal and bare repositories and keeps the existing "not a repo" behavior for non-repo directories. Fixes #1238, reported and LGTM'd by maintainers there with this exact fix; no PR had been opened for it yet. Adds tests/is-git-repo.bats covering: a normal repo, a bare repo, and a plain (non-repo) directory. * Fix ruff lint failures in scripts/checkstyle.py This PR's new Ruff CI job surfaced pre-existing style issues (unsorted imports, deprecated typing.List/Dict, nested ifs, bare exit()) in checkstyle.py. Cleaned these up so the newly added lint job passes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
17 lines
381 B
Plaintext
Executable file
17 lines
381 B
Plaintext
Executable file
#
|
|
# check whether current directory is inside a git repository
|
|
#
|
|
|
|
is_git_repo() {
|
|
# --git-dir succeeds for both normal and bare repositories, whereas
|
|
# --show-toplevel fails inside a bare repository (it has no working tree).
|
|
git rev-parse --git-dir > /dev/null 2>&1
|
|
result=$?
|
|
if test $result != 0; then
|
|
>&2 echo 'Not a git repo!'
|
|
exit $result
|
|
fi
|
|
}
|
|
|
|
is_git_repo
|