diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-05-27 09:54:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-27 09:54:28 -0400 |
| commit | 1af3b46e902378dcbdf104a32ddae1644c64c366 (patch) | |
| tree | eb40b22d94abbd6860bb2ec1eac5b1ca62ea542a /src/git-directory-helper.ts | |
| parent | 31d9f35c90667154e76ccca096898caab3e5bba7 (diff) | |
Fetch all history for all tags and branches when fetch-depth=0 (#258)
Diffstat (limited to 'src/git-directory-helper.ts')
| -rw-r--r-- | src/git-directory-helper.ts | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/git-directory-helper.ts b/src/git-directory-helper.ts index 3866866..e792190 100644 --- a/src/git-directory-helper.ts +++ b/src/git-directory-helper.ts @@ -5,13 +5,13 @@ import * as fsHelper from './fs-helper' import * as io from '@actions/io' import * as path from 'path' import {IGitCommandManager} from './git-command-manager' -import {IGitSourceSettings} from './git-source-settings' export async function prepareExistingDirectory( git: IGitCommandManager | undefined, repositoryPath: string, repositoryUrl: string, - clean: boolean + clean: boolean, + ref: string ): Promise<void> { assert.ok(repositoryPath, 'Expected repositoryPath to be defined') assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined') @@ -56,10 +56,26 @@ export async function prepareExistingDirectory( await git.branchDelete(false, branch) } - // Remove all refs/remotes/origin/* to avoid conflicts - branches = await git.branchList(true) - for (const branch of branches) { - await git.branchDelete(true, branch) + // Remove any conflicting refs/remotes/origin/* + // Example 1: Consider ref is refs/heads/foo and previously fetched refs/remotes/origin/foo/bar + // Example 2: Consider ref is refs/heads/foo/bar and previously fetched refs/remotes/origin/foo + if (ref) { + ref = ref.startsWith('refs/') ? ref : `refs/heads/${ref}` + if (ref.startsWith('refs/heads/')) { + const upperName1 = ref.toUpperCase().substr('REFS/HEADS/'.length) + const upperName1Slash = `${upperName1}/` + branches = await git.branchList(true) + for (const branch of branches) { + const upperName2 = branch.substr('origin/'.length).toUpperCase() + const upperName2Slash = `${upperName2}/` + if ( + upperName1.startsWith(upperName2Slash) || + upperName2.startsWith(upperName1Slash) + ) { + await git.branchDelete(true, branch) + } + } + } } core.endGroup() |
