aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoroxalica <oxalicc@pm.me>2021-09-24 22:01:27 +0800
committeroxalica <oxalicc@pm.me>2021-09-24 22:09:49 +0800
commit81b8e910a0261572a3fedabfce5318fec3ffc95c (patch)
tree21dd98d11c9720b061bae020ee3ba14c8ef773ac /src
parent362d8f925eae95f1feb912ada7e401c56d6f7398 (diff)
Explicitly set initial branch name for git
Diffstat (limited to 'src')
-rw-r--r--src/libfetchers/git.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index bfc58f7a1..8468d2afc 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -13,6 +13,12 @@ using namespace std::string_literals;
namespace nix::fetchers {
+// Explicit initial branch of our bare repo to suppress warnings from new version of git.
+// The value itself does not matter, since we always fetch a specific revision or branch.
+// It is set with `-c init.defaultBranch=` instead of `--initial-branch=` to stay compatible with
+// old version of git, which will ignore unrecognized `-c` options.
+const std::string gitInitialBranch = "__nix_dummy_branch";
+
static std::string readHead(const Path & path)
{
return chomp(runProgram("git", true, { "-C", path, "rev-parse", "--abbrev-ref", "HEAD" }));
@@ -324,7 +330,7 @@ struct GitInputScheme : InputScheme
lockFile(lock.get(), ltWrite, true);
if (!pathExists(cacheDir)) {
- runProgram("git", true, { "init", "--bare", repoDir });
+ runProgram("git", true, { "-c", "init.defaultBranch=" + gitInitialBranch, "init", "--bare", repoDir });
}
deleteLockFile(cacheDirLock, lock.get());
@@ -436,7 +442,7 @@ struct GitInputScheme : InputScheme
Path tmpGitDir = createTempDir();
AutoDelete delTmpGitDir(tmpGitDir, true);
- runProgram("git", true, { "init", tmpDir, "--separate-git-dir", tmpGitDir });
+ runProgram("git", true, { "-c", "init.defaultBranch=" + gitInitialBranch, "init", tmpDir, "--separate-git-dir", tmpGitDir });
// TODO: repoDir might lack the ref (it only checks if rev
// exists, see FIXME above) so use a big hammer and fetch
// everything to ensure we get the rev.