From ca444bd9c16ab481e681256de3a891b86933a14d Mon Sep 17 00:00:00 2001 From: Markus Schulz <msc@onesty-tech.de> Date: Fri, 6 Jan 2023 10:48:16 +0100 Subject: [PATCH] feat(git): allow to fetch with ref-specs (#19697) --- lib/util/git/index.spec.ts | 11 +++++++++++ lib/util/git/index.ts | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index 30bc0924b8..1d17075dae 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -1033,4 +1033,15 @@ describe('util/git/index', () => { expect(await git.getSubmodules()).toHaveLength(0); }); }); + + describe('fetchRevSpec()', () => { + it('fetchRevSpec()', async () => { + await git.fetchRevSpec( + `refs/heads/${defaultBranch}:refs/heads/other/${defaultBranch}` + ); + //checkout this duplicate + const sha = await git.checkoutBranch(`other/${defaultBranch}`); + expect(sha).toBe(git.getBranchCommit(defaultBranch)); + }); + }); }); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 5cdeb178aa..1b2c749cfb 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -229,6 +229,10 @@ async function fetchBranchCommits(): Promise<void> { } } +export async function fetchRevSpec(revSpec: string): Promise<void> { + await gitRetry(() => git.fetch(['origin', revSpec])); +} + export async function initRepo(args: StorageConfig): Promise<void> { config = { ...args } as any; config.ignoredAuthors = []; -- GitLab