commit: 1696966564510e8359e3e29681dc1326c37c6e0b Author: John Helmert III <ajak <AT> gentoo <DOT> org> AuthorDate: Thu Nov 3 02:48:59 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=16969665
sync: git: `git clean` the repo before updating With a shallow clone, git may leave orphaned files if the remote moves from state X -> X-1. If on pulling again, state X is returned, git will then abort to avoid clobbering untracked files. Bug: https://bugs.gentoo.org/887025 Signed-off-by: John Helmert III <ajak <AT> gentoo.org> Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/sync/modules/git/git.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/portage/sync/modules/git/git.py b/lib/portage/sync/modules/git/git.py index 8602fecba..e768e6861 100644 --- a/lib/portage/sync/modules/git/git.py +++ b/lib/portage/sync/modules/git/git.py @@ -250,6 +250,24 @@ class GitSync(NewBase): if not self.verify_head(revision="refs/remotes/%s" % remote_branch): return (1, False) + # Clean up the repo before trying to sync to upstream's + clean_cmd = [self.bin_command, "clean", "--force", "-d", "-x"] + + if quiet: + clean_cmd.append("--quiet") + + portage.process.spawn( + clean_cmd, + cwd=portage._unicode_encode(self.repo.location), + **self.spawn_kwargs, + ) + + if exitcode != os.EX_OK: + msg = "!!! git clean error in %s" % self.repo.location + self.logger(self.xterm_titles, msg) + writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) + return (exitcode, False) + # `git diff --quiet` returns 0 on a clean tree and 1 otherwise is_clean = ( portage.process.spawn(
