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 <marek.belisko@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2019-09-20 06:31:04 +02:00
parent acc60f4f3a
commit 26a1a0b03b

View File

@ -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]