diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-18 23:33:26 -0400 |
|---|---|---|
| committer | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-18 23:33:26 -0400 |
| commit | d35c5b0d45c2389911e8fa57f5a409dc7eb4eba9 (patch) | |
| tree | 9504842130011e5303867f926b8e6016a715323e /src/git-directory-helper.ts | |
| parent | 6f1b729011b34bc28608462b6293df85180aba9c (diff) | |
use token for workflow repo
Diffstat (limited to 'src/git-directory-helper.ts')
| -rw-r--r-- | src/git-directory-helper.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/git-directory-helper.ts b/src/git-directory-helper.ts index bfaa4a9..a7d6ae8 100644 --- a/src/git-directory-helper.ts +++ b/src/git-directory-helper.ts @@ -1,18 +1,30 @@ +import * as assert from 'assert' import * as core from '@actions/core' import * as fs from 'fs' 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, + preferredRemoteUrl: string, + allowedRemoteUrls: string[], clean: boolean ): Promise<void> { + assert.ok(repositoryPath, 'Expected repositoryPath to be defined') + assert.ok(preferredRemoteUrl, 'Expected preferredRemoteUrl to be defined') + assert.ok(allowedRemoteUrls, 'Expected allowedRemoteUrls to be defined') + assert.ok(allowedRemoteUrls.length, 'Expected allowedRemoteUrls to have at least one value') + + // Indicates whether to delete the directory contents let remove = false + // The remote URL + let remoteUrl: string + // Check whether using git or REST API if (!git) { remove = true @@ -20,7 +32,7 @@ export async function prepareExistingDirectory( // Fetch URL does not match else if ( !fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) || - repositoryUrl !== (await git.tryGetFetchUrl()) + allowedRemoteUrls.indexOf((remoteUrl = await git.tryGetRemoteUrl())) < 0 ) { remove = true } else { @@ -72,6 +84,11 @@ export async function prepareExistingDirectory( ) } } + + // Update to the preferred remote URL + if (remoteUrl !== preferredRemoteUrl) { + await git.setRemoteUrl(preferredRemoteUrl) + } } catch (error) { core.warning( `Unable to prepare the existing repository. The repository will be recreated instead.` |
