From 26a1a0b03b402bb30ddc126f967b46df264c284a Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Fri, 20 Sep 2019 06:31:04 +0200 Subject: [PATCH] Create from local branch before applying patches with git If refspec is pointing to an upstream branch name, the checkout for a second run will not reset a repo back to the upstream commit. That is because we applied the repo patches to a local branch that carries the name of the upstream one. Fix that by switching to local branch prior to applying any patches. Reported-by: Belisko Marek Signed-off-by: Jan Kiszka --- kas/repos.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kas/repos.py b/kas/repos.py index 4f74f4b..5192c2b 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -247,9 +247,14 @@ class RepoImpl(Repo): """ Applies patches to a repository asynchronously. """ - if self.operations_disabled: + if self.operations_disabled or not self._patches: return 0 + (retc, _) = yield from run_cmd_async(self.prepare_patches_cmd(), + cwd=self.path) + if retc: + return retc + my_patches = [] for patch in self._patches: @@ -289,9 +294,6 @@ class RepoImpl(Repo): patch['id']) return 1 - if len(my_patches) == 0: - return 0 - for path in my_patches: cmd = self.apply_patches_file_cmd(path) (retc, output) = yield from run_cmd_async(cmd, cwd=self.path) @@ -359,6 +361,10 @@ class GitRepo(RepoImpl): return ['git', 'checkout', '-q', '{refspec}'.format(refspec=self.refspec)] + def prepare_patches_cmd(self): + return ['git', 'checkout', '-q', '-B', + 'patched-{refspec}'.format(refspec=self.refspec)] + def apply_patches_file_cmd(self, path): return ['git', 'apply', path] @@ -395,6 +401,10 @@ class MercurialRepo(RepoImpl): def checkout_cmd(self): return ['hg', 'checkout', '{refspec}'.format(refspec=self.refspec)] + def prepare_patches_cmd(self): + return ['hg', 'branch', '-f', + 'patched-{refspec}'.format(refspec=self.refspec)] + def apply_patches_file_cmd(self, path): return ['hg', 'import', '--no-commit', path]