From 7f5a31d79ee255c1b6954b4138f7848805ad778f Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 3 Jul 2023 14:46:55 +0200 Subject: just-mr: Fix handling of .gitignore files in git repositories The command 'git add .' does not include paths found in .gitignore files in the directory tree where the command is issued. This is not the desired behaviour, as we expect for a tree with a given commit id to contain all of the entries, irrespective of their meaning to Git. This commit addresses the issue as described. For the just-mr.py script we modified the staging command to 'git add -f .'. For the compiled just-mr, simply adding the force flag to 'git_index_add_all' did not work as intended for files found in ignored subdirectories. This is a known libgit2 issue which has been fixed in v1.6.3. Until we can upgrade our libgit2 version, a workaround was implemented: we recursively read the directory entries ourselves and add each of them iteratively using 'git_index_add_bypath', making sure to ignore the root '.git' subtree (which cannot be staged). At the moment the handling of Git submodules remains an open issue, as Git does not allow '.git' subtrees to be forcefully added to the index, and thus such directory entries will currently not be considered as part of a git tree. This however is consistent behavior between Git and libgit2. (cherry picked from f234434a6fa2118b10765cff2f75bbc3196fec39) --- src/buildtool/file_system/git_cas.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/buildtool/file_system/git_cas.cpp') diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp index 7bddf6b3..ada77f3f 100644 --- a/src/buildtool/file_system/git_cas.cpp +++ b/src/buildtool/file_system/git_cas.cpp @@ -156,9 +156,14 @@ auto GitCAS::OpenODB(std::filesystem::path const& repo_path) noexcept -> bool { git_odb* odb_ptr{nullptr}; git_repository_odb(&odb_ptr, repo); odb_.reset(odb_ptr); // retain odb pointer - // set root - std::filesystem::path git_path = - ToNormalPath(git_repository_path(repo)); + // set root + std::filesystem::path git_path{}; + if (git_repository_is_bare(repo) != 0) { + git_path = ToNormalPath((git_repository_path(repo))); + } + else { + git_path = ToNormalPath(git_repository_workdir(repo)); + } if (not git_path.is_absolute()) { try { git_path = std::filesystem::absolute(git_path); -- cgit v1.2.3