public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v2] Create from local branch before applying patches with git
@ 2019-09-21 11:07 Jan Kiszka
  2019-09-21 11:07 ` Jan Kiszka
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kiszka @ 2019-09-21 11:07 UTC (permalink / raw)
  To: isar-users; +Cc: Belisko Marek, Henning Schild

From: Jan Kiszka <jan.kiszka@siemens.com>

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

Changes in v2:
 - rebased over next
 - add hg support
 - use local branch also with git

 kas/repos.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/kas/repos.py b/kas/repos.py
index 4f74f4b..113a67f 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:
@@ -359,6 +364,9 @@ class GitRepo(RepoImpl):
         return ['git', 'checkout', '-q',
                 '{refspec}'.format(refspec=self.refspec)]
 
+    def prepare_patches_cmd(self):
+        return ['git', 'checkout', '-q', '-B', 'local-kas-patches']
+
     def apply_patches_file_cmd(self, path):
         return ['git', 'apply', path]
 
@@ -395,6 +403,9 @@ class MercurialRepo(RepoImpl):
     def checkout_cmd(self):
         return ['hg', 'checkout', '{refspec}'.format(refspec=self.refspec)]
 
+    def prepare_patches_cmd(self):
+        return ['hg', 'branch', '-f', 'local-kas-patches']
+
     def apply_patches_file_cmd(self, path):
         return ['hg', 'import', '--no-commit', path]
 
-- 
2.16.4


-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Create from local branch before applying patches with git
  2019-09-21 11:07 [PATCH v2] Create from local branch before applying patches with git Jan Kiszka
@ 2019-09-21 11:07 ` Jan Kiszka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2019-09-21 11:07 UTC (permalink / raw)
  To: isar-users

Ignore, wrong list, sorry.

Jan

On 21.09.19 13:07, [ext] Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> 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>
> ---
> 
> Changes in v2:
>   - rebased over next
>   - add hg support
>   - use local branch also with git
> 
>   kas/repos.py | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/kas/repos.py b/kas/repos.py
> index 4f74f4b..113a67f 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:
> @@ -359,6 +364,9 @@ class GitRepo(RepoImpl):
>           return ['git', 'checkout', '-q',
>                   '{refspec}'.format(refspec=self.refspec)]
>   
> +    def prepare_patches_cmd(self):
> +        return ['git', 'checkout', '-q', '-B', 'local-kas-patches']
> +
>       def apply_patches_file_cmd(self, path):
>           return ['git', 'apply', path]
>   
> @@ -395,6 +403,9 @@ class MercurialRepo(RepoImpl):
>       def checkout_cmd(self):
>           return ['hg', 'checkout', '{refspec}'.format(refspec=self.refspec)]
>   
> +    def prepare_patches_cmd(self):
> +        return ['hg', 'branch', '-f', 'local-kas-patches']
> +
>       def apply_patches_file_cmd(self, path):
>           return ['hg', 'import', '--no-commit', path]
>   
> 
-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-21 11:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-21 11:07 [PATCH v2] Create from local branch before applying patches with git Jan Kiszka
2019-09-21 11:07 ` Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox