commit: cc20629da347393e6987fa58231e4b773ca0a5e7 Author: John Helmert III <ajak <AT> gentoo <DOT> org> AuthorDate: Sun Nov 20 04:47:13 2022 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed Dec 21 01:28:03 2022 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=cc20629d
sync: git: add GIT_CEILING_DIRECTORIES for update operations Bug: https://bugs.gentoo.org/887025 Signed-off-by: John Helmert III <ajak <AT> gentoo.org> Closes: https://github.com/gentoo/portage/pull/939 Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/sync/modules/git/git.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/portage/sync/modules/git/git.py b/lib/portage/sync/modules/git/git.py index e768e6861..7af665e5f 100644 --- a/lib/portage/sync/modules/git/git.py +++ b/lib/portage/sync/modules/git/git.py @@ -116,6 +116,22 @@ class GitSync(NewBase): return (os.EX_OK, True) + def _gen_ceiling_string(self, path): + """ + Iteratively generate a colon delimited string of all of the + given path's parents, for use with GIT_CEILING_DIRECTORIES + """ + path = self.repo.location + directories = [] + + while True: + if path == "/": + break + path = os.path.dirname(path) + directories.append(path) + + return ":".join(directories) + def update(self): """Update existing git repository, and ignore the syncuri. We are going to trust the user and assume that the user is in the branch @@ -126,6 +142,13 @@ class GitSync(NewBase): return (1, False) git_cmd_opts = "" quiet = self.settings.get("PORTAGE_QUIET") == "1" + + # We don't want to operate with a .git outside of the given + # repo in any circumstances. + self.spawn_kwargs["env"].update( + {"GIT_CEILING_DIRECTORIES": self._gen_ceiling_string(self.repo.location)} + ) + if self.repo.module_specific_options.get("sync-git-env"): shlexed_env = shlex_split(self.repo.module_specific_options["sync-git-env"]) env = {
