Skip to content

Commit e26eddf

Browse files
committed
libfetchers/git: Allow Git Remote Helpers
Remote helpers are programs that are invoked when Git needs to interact with remote repositories that it does not support natively, see <https://git-scm.com/docs/gitremote-helpers> The following two changes make use of such remote helpers possible in conjunction with Nix: 1. Relax URL scheme filtering for the Git fetcher, such that unknown URL schemes are not rejected directly. In case there is no corresponding remote helper available, the following output is produced: warning: URL scheme 'git+invalid' is non-standard and requires 'git-remote-invalid'. git: 'remote-invalid' is not a git command. See 'git --help'. error: program 'git' failed with exit code 128 2. Add `GIT_DIR` to the environment, since this is required by remote helpers.
1 parent 8c4c215 commit e26eddf

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/libfetchers/git-utils.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "environment-variables.hh"
12
#include "git-utils.hh"
23
#include "fs-input-accessor.hh"
34
#include "input-accessor.hh"
@@ -377,18 +378,23 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
377378
auto dir = this->path;
378379
Strings gitArgs;
379380
if (shallow) {
380-
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
381+
gitArgs = { "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
381382
}
382383
else {
383-
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--", url, refspec };
384+
gitArgs = { "fetch", "--quiet", "--force", "--", url, refspec };
384385
}
385386

387+
388+
std::map<std::string, std::string> gitEnv = getEnv();
389+
gitEnv.emplace("GIT_DIR", dir.string());
390+
386391
runProgram(RunOptions {
387392
.program = "git",
388393
.searchPath = true,
389394
// FIXME: git stderr messes up our progress indicator, so
390395
// we're using --quiet for now. Should process its stderr.
391396
.args = gitArgs,
397+
.environment = gitEnv,
392398
.input = {},
393399
.isInteractive = true
394400
});

src/libfetchers/unix/git.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,20 @@ struct GitInputScheme : InputScheme
167167
{
168168
std::optional<Input> inputFromURL(const ParsedURL & url, bool requireTree) const override
169169
{
170+
if (url.scheme != "git" && url.scheme.compare(0, 4, "git+") != 0) {
171+
return {};
172+
}
173+
170174
if (url.scheme != "git" &&
171175
url.scheme != "git+http" &&
172176
url.scheme != "git+https" &&
173177
url.scheme != "git+ssh" &&
174-
url.scheme != "git+file") return {};
178+
url.scheme != "git+file") {
179+
warn("URL scheme '%s' is non-standard and requires 'git-remote-%s'.", url.scheme, url.scheme.substr(4, url.scheme.length() - 4));
180+
}
181+
182+
183+
debug("scheme %s looking good", url.scheme);
175184

176185
auto url2(url);
177186
if (hasPrefix(url2.scheme, "git+")) url2.scheme = std::string(url2.scheme, 4);

0 commit comments

Comments
 (0)