Add git submodule fixes from @bjornfor

This fixes fetching repositories with no submodules and also cleans up
.git files in checkouts.
This commit is contained in:
Julian Stecklina 2020-03-02 14:42:19 +01:00 committed by Julian Stecklina
parent ea861be292
commit c8d33de777
3 changed files with 10 additions and 3 deletions

View file

@ -9,6 +9,7 @@ libexpr_SOURCES := $(wildcard $(d)/*.cc) $(wildcard $(d)/primops/*.cc) $(d)/lexe
libexpr_LIBS = libutil libstore libnixrust
libexpr_LDFLAGS =
ifneq ($(OS), FreeBSD)
libexpr_LDFLAGS += -ldl
endif

View file

@ -6,6 +6,7 @@
#include "hash.hh"
#include "tarfile.hh"
#include <filesystem>
#include <sys/time.h>
#include <regex>
@ -182,9 +183,13 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
runProgram("git", true, { "-C", tmpDir, "checkout", "--quiet", "FETCH_HEAD" });
runProgram("git", true, { "-C", tmpDir, "remote", "add", "origin", uri });
runProgram("git", true, { "-C", tmpDir, "submodule", "--quiet", "update", "--init" });
runProgram("git", true, { "-C", tmpDir, "submodule", "--quiet", "update", "--init", "--recursive" });
deletePath(tmpDir + "/.git");
for (const auto& p : std::filesystem::recursive_directory_iterator(tmpDir)) {
if (p.path().filename() == ".git") {
std::filesystem::remove_all(p.path());
}
}
gitInfo.submodules = true;
} else {

View file

@ -47,4 +47,5 @@ pathWithSubmodules=$(nix eval --raw "(builtins.fetchGit { url = file://$rootRepo
[[ ! -e $pathWithoutSubmodules/sub/content ]]
[[ -e $pathWithSubmodules/sub/content ]]
# No .git directory or submodule reference files must be left
test "$(find "$pathWithSubmodules" -name .git)" = ""