summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2016-11-10 03:51:12 -0800
committerJosh Triplett <josh@joshtriplett.org>2016-11-11 14:15:06 -0800
commitc9e967a1b48c7a0b484fd3a4860e9c7a0aa4a319 (patch)
tree09b1595e7b430df00b6e51e736b3f637552c3c04
parent5fe5557e8a8d3fd6a4617c2d8c863c1f62848020 (diff)
downloadlibgit2-c9e967a1b48c7a0b484fd3a4860e9c7a0aa4a319.tar.gz
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.
-rw-r--r--src/repository.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/repository.c b/src/repository.c
index cf3d18a2d..7bdcefd40 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -613,9 +613,10 @@ static int _git_repository_open_ext_from_env(
git_repository_set_odb(repo, odb);
error = git__getenv(&alts_buf, "GIT_ALTERNATE_OBJECT_DIRECTORIES");
- if (error == GIT_ENOTFOUND)
+ if (error == GIT_ENOTFOUND) {
giterr_clear();
- else if (error < 0)
+ error = 0;
+ } else if (error < 0)
goto error;
else {
const char *end;
@@ -638,9 +639,11 @@ static int _git_repository_open_ext_from_env(
}
}
- error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
- if (error < 0)
- goto error;
+ if (git_buf_len(&namespace_buf)) {
+ error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
+ if (error < 0)
+ goto error;
+ }
git_repository_set_index(repo, index);