aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2023-02-07 15:35:32 +0100
committerEelco Dolstra <edolstra@gmail.com>2023-02-07 16:01:36 +0100
commit2edd5cf6184a7955ba82a2aed8bbfa870bfeb15f (patch)
tree73a688e532378dc3255041dbf25fb170ec569499 /src/libfetchers
parent81e75e4bf6083046155a0c1fd6e312b43a60f7da (diff)
Fix the origin URL used for fetching submodules
We cannot use 'actualUrl', because for file:// repos that's not the original URL that the repo was fetched from. This is a problem since submodules may be relative to the original URL. Fixes e.g. nix eval --impure --json --expr 'builtins.fetchTree { type = "git"; url = "/path/to/blender"; submodules = true; }' where /path/to/blender is a clone of https://github.com/blender/blender.git (which has several relative submodules like '../blender-addons.git').
Diffstat (limited to 'src/libfetchers')
-rw-r--r--src/libfetchers/git.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index fb80d248c..8981476e1 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -627,7 +627,17 @@ struct GitInputScheme : InputScheme
runProgram("git", true, { "-C", tmpDir, "checkout", "--quiet", input.getRev()->gitRev() });
- runProgram("git", true, { "-C", tmpDir, "remote", "add", "origin", actualUrl });
+ /* Ensure that we use the correct origin for fetching
+ submodules. This matters for submodules with relative
+ URLs. */
+ if (isLocal) {
+ writeFile(tmpGitDir + "/config", readFile(repoDir + "/" + gitDir + "/config"));
+
+ /* Restore the config.bare setting we may have just
+ nuked. */
+ runProgram("git", true, { "-C", tmpDir, "config", "core.bare", "false" });
+ } else
+ runProgram("git", true, { "-C", tmpDir, "config", "remote.origin.url", actualUrl });
{
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching submodules of '%s'", tmpDir));