Skip to content

Commit c9e967a

Browse files
committed
git_repository_open_ext: fix handling of $GIT_NAMESPACE
The existing code would set a namespace of "" (empty string) with GIT_NAMESPACE unset. In a repository where refs/heads/namespaces/ exists, that can produce incorrect results. Detect that case and avoid setting the namespace at all. Since that makes the last assignment to error conditional, and the previous assignment can potentially get GIT_ENOTFOUND, set error to 0 explicitly to prevent the call from incorrectly failing with GIT_ENOTFOUND.
1 parent 5fe5557 commit c9e967a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/repository.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,10 @@ static int _git_repository_open_ext_from_env(
613613
git_repository_set_odb(repo, odb);
614614

615615
error = git__getenv(&alts_buf, "GIT_ALTERNATE_OBJECT_DIRECTORIES");
616-
if (error == GIT_ENOTFOUND)
616+
if (error == GIT_ENOTFOUND) {
617617
giterr_clear();
618-
else if (error < 0)
618+
error = 0;
619+
} else if (error < 0)
619620
goto error;
620621
else {
621622
const char *end;
@@ -638,9 +639,11 @@ static int _git_repository_open_ext_from_env(
638639
}
639640
}
640641

641-
error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
642-
if (error < 0)
643-
goto error;
642+
if (git_buf_len(&namespace_buf)) {
643+
error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
644+
if (error < 0)
645+
goto error;
646+
}
644647

645648
git_repository_set_index(repo, index);
646649

0 commit comments

Comments
 (0)