From 420bf399b305542765c8a47ffcb50c7f7e10bfa6 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 29 May 2023 08:11:39 +0200 Subject: [PATCH] repos: git: Strip of heads/ prefix when checking out branches If a remote branch is referenced as refs/heads/, also drop the heads/ from the local branch name to have a consistent naming. This wasn't noticed so far because the primary use case of refs/ is addressing symbolic refs in upstream, and the related test case (test_refspec_absolute) was papering over another hidden kas issues while using refs/heads/. Signed-off-by: Jan Kiszka --- kas/repos.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kas/repos.py b/kas/repos.py index dcac1b9..0958544 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -443,7 +443,9 @@ class GitRepo(RepoImpl): def checkout_cmd(self, desired_ref, is_branch): cmd = ['git', 'checkout', '-q', self.remove_ref_prefix(desired_ref)] if is_branch: - cmd.extend(['-B', self.remove_ref_prefix(self.refspec)]) + branch = self.remove_ref_prefix(self.refspec) + branch = branch[branch.startswith('heads/') and len('heads/'):] + cmd.extend(['-B', branch]) if get_context().force_checkout: cmd.append('--force') return cmd