From f1f358bed5110509ed23532a8a57e10b50551a4d Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sun, 28 May 2023 21:25:38 +0200 Subject: [PATCH] repos: git: Always replicate refs/ into local branches on checkout If a refspec addresses an upstream branch which commit happens to be local already, checkout will not properly replicate that into a local branch. Extend contains_refspec_cmd so that it does not falsely report the remotes/origin/ ref as locally available and rather triggers its fetching. The related test case was papering over this issue so far. Adjust it accordingly. Signed-off-by: Jan Kiszka --- kas/repos.py | 5 ++++- tests/test_refspec.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kas/repos.py b/kas/repos.py index 0958544..1c81d3b 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -420,7 +420,10 @@ class GitRepo(RepoImpl): '-m', 'msg'] def contains_refspec_cmd(self): - return ['git', 'cat-file', '-t', self.remove_ref_prefix(self.refspec)] + refspec = self.refspec + if refspec and refspec.startswith('refs/'): + refspec = 'remotes/origin/' + self.remove_ref_prefix(refspec) + return ['git', 'cat-file', '-t', refspec] def fetch_cmd(self): cmd = ['git', 'fetch', '-q'] diff --git a/tests/test_refspec.py b/tests/test_refspec.py index f012031..6a42aa8 100644 --- a/tests/test_refspec.py +++ b/tests/test_refspec.py @@ -78,8 +78,8 @@ def test_refspec_absolute(changedir, tmpdir): kas.kas(['shell', 'test3.yml', '-c', 'true']) (rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], cwd='kas_abs', fail=False, liveupdate=False) - assert rc != 0 - assert output.strip() == '' + assert rc == 0 + assert output.strip() == 'refs/heads/master' (rc, output_kas_abs) = run_cmd(['git', 'rev-parse', 'HEAD'], cwd='kas_abs', fail=False, liveupdate=False) assert rc == 0