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 <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2023-05-28 21:25:38 +02:00
parent 420bf399b3
commit f1f358bed5
2 changed files with 6 additions and 3 deletions

View File

@ -420,7 +420,10 @@ class GitRepo(RepoImpl):
'-m', 'msg'] '-m', 'msg']
def contains_refspec_cmd(self): 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): def fetch_cmd(self):
cmd = ['git', 'fetch', '-q'] cmd = ['git', 'fetch', '-q']

View File

@ -78,8 +78,8 @@ def test_refspec_absolute(changedir, tmpdir):
kas.kas(['shell', 'test3.yml', '-c', 'true']) kas.kas(['shell', 'test3.yml', '-c', 'true'])
(rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'], (rc, output) = run_cmd(['git', 'symbolic-ref', '-q', 'HEAD'],
cwd='kas_abs', fail=False, liveupdate=False) cwd='kas_abs', fail=False, liveupdate=False)
assert rc != 0 assert rc == 0
assert output.strip() == '' assert output.strip() == 'refs/heads/master'
(rc, output_kas_abs) = run_cmd(['git', 'rev-parse', 'HEAD'], (rc, output_kas_abs) = run_cmd(['git', 'rev-parse', 'HEAD'],
cwd='kas_abs', fail=False, liveupdate=False) cwd='kas_abs', fail=False, liveupdate=False)
assert rc == 0 assert rc == 0