mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
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.
33 lines
659 B
Bash
33 lines
659 B
Bash
# shellcheck shell=bash
|
|
|
|
source "$BATS_TEST_DIRNAME/test_util.sh"
|
|
|
|
setup_file() {
|
|
test_util.setup_file
|
|
}
|
|
|
|
setup() {
|
|
test_util.cd_test
|
|
}
|
|
|
|
@test "is_git_repo succeeds inside a normal (non-bare) repository" {
|
|
test_util.git_init
|
|
|
|
run bash "$BATS_TEST_DIRNAME/../helper/is-git-repo"
|
|
assert_success
|
|
}
|
|
|
|
@test "is_git_repo succeeds inside a bare repository (see #1238)" {
|
|
git init --bare --initial-branch main repo.git
|
|
cd repo.git
|
|
|
|
run bash "$BATS_TEST_DIRNAME/../helper/is-git-repo"
|
|
assert_success
|
|
}
|
|
|
|
@test "is_git_repo fails outside of a repository" {
|
|
run bash "$BATS_TEST_DIRNAME/../helper/is-git-repo"
|
|
assert_failure
|
|
assert_output 'Not a git repo!'
|
|
}
|