aboutsummaryrefslogtreecommitdiffstats
path: root/t/t0003-attributes.sh
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-07 06:53:05 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-06 22:50:49 -0700
commit813f17fd6bd9289185a50f1d1179393bd1339b9b (patch)
treea13ed7ac2aaed959edcab80710fc575ec7555832 /t/t0003-attributes.sh
parentbbb82f8dc88aee588a35615fdb10862f3b41e16c (diff)
downloadgit-813f17fd6bd9289185a50f1d1179393bd1339b9b.tar.gz
attr: fix BUG() when parsing attrs outside of repo
If either the `--attr-source` option or the `GIT_ATTR_SOURCE` envvar are set, then `compute_default_attr_source()` will try to look up the value as a treeish. It is possible to hit that function while outside of a Git repository though, for example when using `git grep --no-index`. In that case, Git will hit a bug because we try to look up the main ref store outside of a repository. Handle the case gracefully and detect when we try to look up an attr source without a repository. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t0003-attributes.sh')
-rwxr-xr-xt/t0003-attributes.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index d755cc3c29..72fadca1e8 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -434,6 +434,21 @@ test_expect_success 'precedence of --attr-source, GIT_ATTR_SOURCE, then attr.tre
)
'
+test_expect_success 'diff without repository with attr source' '
+ mkdir -p "$TRASH_DIRECTORY/outside/nongit" &&
+ (
+ cd "$TRASH_DIRECTORY/outside/nongit" &&
+ GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/outside" &&
+ export GIT_CEILING_DIRECTORIES &&
+ touch file &&
+ cat >expect <<-EOF &&
+ fatal: cannot use --attr-source or GIT_ATTR_SOURCE without repo
+ EOF
+ test_must_fail env GIT_ATTR_SOURCE=HEAD git grep --no-index foo file 2>err &&
+ test_cmp expect err
+ )
+'
+
test_expect_success 'bare repository: with --source' '
(
cd bare.git &&