aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.c15
-rwxr-xr-xt/t1305-config-include.sh2
2 files changed, 10 insertions, 7 deletions
diff --git a/config.c b/config.c
index 1266eab086..a11bb85da3 100644
--- a/config.c
+++ b/config.c
@@ -306,13 +306,16 @@ static int include_by_branch(struct config_include_data *data,
int flags;
int ret;
struct strbuf pattern = STRBUF_INIT;
- const char *refname = (!data->repo || !data->repo->gitdir) ?
- NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
- "HEAD", 0, NULL, &flags);
- const char *shortname;
+ const char *refname, *shortname;
- if (!refname || !(flags & REF_ISSYMREF) ||
- !skip_prefix(refname, "refs/heads/", &shortname))
+ if (!data->repo || data->repo->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
+ return 0;
+
+ refname = refs_resolve_ref_unsafe(get_main_ref_store(data->repo),
+ "HEAD", 0, NULL, &flags);
+ if (!refname ||
+ !(flags & REF_ISSYMREF) ||
+ !skip_prefix(refname, "refs/heads/", &shortname))
return 0;
strbuf_add(&pattern, cond, cond_len);
diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh
index ad08db7230..517d6c8693 100755
--- a/t/t1305-config-include.sh
+++ b/t/t1305-config-include.sh
@@ -389,7 +389,7 @@ test_expect_success 'onbranch without repository' '
test_must_fail nongit git config get foo.bar
'
-test_expect_failure 'onbranch without repository but explicit nonexistent Git directory' '
+test_expect_success 'onbranch without repository but explicit nonexistent Git directory' '
test_when_finished "rm -f .gitconfig config.inc" &&
git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc &&
git config set -f config.inc foo.bar baz &&