mirror of
https://github.com/actions/checkout.git
synced 2026-06-14 16:28:39 +07:00
use token for workflow repo
This commit is contained in:
parent
9a3a9ade82
commit
85a425b582
@ -725,6 +725,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
setEnvironmentVariable: jest.fn((name: string, value: string) => {
|
setEnvironmentVariable: jest.fn((name: string, value: string) => {
|
||||||
git.env[name] = value
|
git.env[name] = value
|
||||||
}),
|
}),
|
||||||
|
setRemoteUrl: jest.fn(),
|
||||||
submoduleForeach: jest.fn(async () => {
|
submoduleForeach: jest.fn(async () => {
|
||||||
return ''
|
return ''
|
||||||
}),
|
}),
|
||||||
@ -748,7 +749,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
tryDisableAutomaticGarbageCollection: jest.fn(),
|
tryDisableAutomaticGarbageCollection: jest.fn(),
|
||||||
tryGetFetchUrl: jest.fn(),
|
tryGetRemoteUrl: jest.fn(),
|
||||||
tryReset: jest.fn()
|
tryReset: jest.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,6 +758,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
clean: true,
|
clean: true,
|
||||||
commit: '',
|
commit: '',
|
||||||
fetchDepth: 1,
|
fetchDepth: 1,
|
||||||
|
isWorkflowRepository: true,
|
||||||
lfs: false,
|
lfs: false,
|
||||||
submodules: false,
|
submodules: false,
|
||||||
nestedSubmodules: false,
|
nestedSubmodules: false,
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import {IGitCommandManager} from '../lib/git-command-manager'
|
|||||||
|
|
||||||
const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
|
const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
|
||||||
let repositoryPath: string
|
let repositoryPath: string
|
||||||
let repositoryUrl: string
|
let httpsUrl: string
|
||||||
|
let sshUrl: string
|
||||||
let clean: boolean
|
let clean: boolean
|
||||||
let git: IGitCommandManager
|
let git: IGitCommandManager
|
||||||
|
|
||||||
@ -40,7 +41,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,7 +64,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -87,7 +90,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -108,7 +112,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -136,7 +141,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -155,14 +161,15 @@ describe('git-directory-helper tests', () => {
|
|||||||
await setup(removesContentsWhenDifferentRepositoryUrl)
|
await setup(removesContentsWhenDifferentRepositoryUrl)
|
||||||
clean = false
|
clean = false
|
||||||
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
|
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
|
||||||
const differentRepositoryUrl =
|
const differentRemoteUrl =
|
||||||
'https://github.com/my-different-org/my-different-repo'
|
'https://github.com/my-different-org/my-different-repo'
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
differentRepositoryUrl,
|
differentRemoteUrl,
|
||||||
|
[differentRemoteUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -186,7 +193,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -211,7 +219,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -235,7 +244,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
undefined,
|
undefined,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -259,7 +269,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -289,7 +300,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -319,7 +331,8 @@ describe('git-directory-helper tests', () => {
|
|||||||
await gitDirectoryHelper.prepareExistingDirectory(
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
git,
|
git,
|
||||||
repositoryPath,
|
repositoryPath,
|
||||||
repositoryUrl,
|
httpsUrl,
|
||||||
|
[httpsUrl, sshUrl],
|
||||||
clean
|
clean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -329,6 +342,30 @@ describe('git-directory-helper tests', () => {
|
|||||||
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1')
|
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1')
|
||||||
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2')
|
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const updatesRemoteUrl = 'updates remote URL'
|
||||||
|
it(updatesRemoteUrl, async () => {
|
||||||
|
// Arrange
|
||||||
|
await setup(updatesRemoteUrl)
|
||||||
|
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await gitDirectoryHelper.prepareExistingDirectory(
|
||||||
|
git,
|
||||||
|
repositoryPath,
|
||||||
|
sshUrl,
|
||||||
|
[sshUrl, httpsUrl],
|
||||||
|
clean
|
||||||
|
)
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
const files = await fs.promises.readdir(repositoryPath)
|
||||||
|
expect(files.sort()).toEqual(['.git', 'my-file'])
|
||||||
|
expect(git.isDetached).toHaveBeenCalled()
|
||||||
|
expect(git.branchList).toHaveBeenCalled()
|
||||||
|
expect(core.warning).not.toHaveBeenCalled()
|
||||||
|
expect(git.setRemoteUrl).toHaveBeenCalledWith(sshUrl)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
async function setup(testName: string): Promise<void> {
|
async function setup(testName: string): Promise<void> {
|
||||||
@ -338,8 +375,9 @@ async function setup(testName: string): Promise<void> {
|
|||||||
repositoryPath = path.join(testWorkspace, testName)
|
repositoryPath = path.join(testWorkspace, testName)
|
||||||
await fs.promises.mkdir(path.join(repositoryPath, '.git'), {recursive: true})
|
await fs.promises.mkdir(path.join(repositoryPath, '.git'), {recursive: true})
|
||||||
|
|
||||||
// Repository URL
|
// Remote URLs
|
||||||
repositoryUrl = 'https://github.com/my-org/my-repo'
|
httpsUrl = 'https://github.com/my-org/my-repo'
|
||||||
|
sshUrl = 'git@github.com:my-org/my-repo'
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
clean = true
|
clean = true
|
||||||
@ -365,6 +403,7 @@ async function setup(testName: string): Promise<void> {
|
|||||||
remoteAdd: jest.fn(),
|
remoteAdd: jest.fn(),
|
||||||
removeEnvironmentVariable: jest.fn(),
|
removeEnvironmentVariable: jest.fn(),
|
||||||
setEnvironmentVariable: jest.fn(),
|
setEnvironmentVariable: jest.fn(),
|
||||||
|
setRemoteUrl: jest.fn(),
|
||||||
submoduleForeach: jest.fn(),
|
submoduleForeach: jest.fn(),
|
||||||
submoduleSync: jest.fn(),
|
submoduleSync: jest.fn(),
|
||||||
submoduleUpdate: jest.fn(),
|
submoduleUpdate: jest.fn(),
|
||||||
@ -374,10 +413,10 @@ async function setup(testName: string): Promise<void> {
|
|||||||
}),
|
}),
|
||||||
tryConfigUnset: jest.fn(),
|
tryConfigUnset: jest.fn(),
|
||||||
tryDisableAutomaticGarbageCollection: jest.fn(),
|
tryDisableAutomaticGarbageCollection: jest.fn(),
|
||||||
tryGetFetchUrl: jest.fn(async () => {
|
tryGetRemoteUrl: jest.fn(async () => {
|
||||||
// Sanity check - this function shouldn't be called when the .git directory doesn't exist
|
// Sanity check - this function shouldn't be called when the .git directory doesn't exist
|
||||||
await fs.promises.stat(path.join(repositoryPath, '.git'))
|
await fs.promises.stat(path.join(repositoryPath, '.git'))
|
||||||
return repositoryUrl
|
return httpsUrl
|
||||||
}),
|
}),
|
||||||
tryReset: jest.fn(async () => {
|
tryReset: jest.fn(async () => {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user