diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index a4a00374c19..acc623c5d3e 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1,3 +1,4 @@ +#include "environment-variables.hh" #include "git-utils.hh" #include "fs-input-accessor.hh" #include "input-accessor.hh" @@ -377,18 +378,23 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this auto dir = this->path; Strings gitArgs; if (shallow) { - gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec }; + gitArgs = { "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec }; } else { - gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--", url, refspec }; + gitArgs = { "fetch", "--quiet", "--force", "--", url, refspec }; } + + std::map gitEnv = getEnv(); + gitEnv.emplace("GIT_DIR", dir.string()); + runProgram(RunOptions { .program = "git", .searchPath = true, // FIXME: git stderr messes up our progress indicator, so // we're using --quiet for now. Should process its stderr. .args = gitArgs, + .environment = gitEnv, .input = {}, .isInteractive = true }); diff --git a/src/libfetchers/unix/git.cc b/src/libfetchers/unix/git.cc index 18915c0a7a0..b980e64317f 100644 --- a/src/libfetchers/unix/git.cc +++ b/src/libfetchers/unix/git.cc @@ -167,11 +167,16 @@ struct GitInputScheme : InputScheme { std::optional inputFromURL(const ParsedURL & url, bool requireTree) const override { + if (url.scheme != "git" && url.scheme.compare(0, 4, "git+") != 0) + return {}; + if (url.scheme != "git" && url.scheme != "git+http" && url.scheme != "git+https" && url.scheme != "git+ssh" && - url.scheme != "git+file") return {}; + url.scheme != "git+file") + warn("URL scheme '%s' is non-standard and requires 'git-remote-%s'.", url.scheme, url.scheme.substr(4, url.scheme.length() - 4)); + auto url2(url); if (hasPrefix(url2.scheme, "git+")) url2.scheme = std::string(url2.scheme, 4);