mirror of
https://github.com/actions/checkout.git
synced 2025-11-07 05:26:55 +00:00
Compare commits
7 commits
1c659197a5
...
e2cf98d5fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2cf98d5fa | ||
|
|
71cf2267d8 | ||
|
|
0548471950 | ||
|
|
49528c1b57 | ||
|
|
f3e6cc288d | ||
|
|
6b47c9436e | ||
|
|
df9ce67227 |
5 changed files with 257 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ _temp/
|
|||
lib/
|
||||
node_modules/
|
||||
.vscode/
|
||||
.idea/
|
||||
|
|
|
|||
11
README.md
11
README.md
|
|
@ -1,6 +1,13 @@
|
|||
[](https://github.com/actions/checkout/actions/workflows/test.yml)
|
||||
|
||||
# Checkout V5
|
||||
# Checkout v6-beta
|
||||
|
||||
## What's new
|
||||
|
||||
- Updated `persist-credentials` to store the credentials under `$RUNNER_TEMP` instead of directly in the local git config.
|
||||
- This requires a minimum Actions Runner version of [v2.329.0](https://github.com/actions/runner/releases/tag/v2.329.0) to access the persisted credentials for [Docker container action](https://docs.github.com/en/actions/tutorials/use-containerized-services/create-a-docker-container-action) scenarios.
|
||||
|
||||
# Checkout v5
|
||||
|
||||
## What's new
|
||||
|
||||
|
|
@ -8,7 +15,7 @@
|
|||
- This requires a minimum Actions Runner version of [v2.327.1](https://github.com/actions/runner/releases/tag/v2.327.1) to run.
|
||||
|
||||
|
||||
# Checkout V4
|
||||
# Checkout v4
|
||||
|
||||
This action checks-out your repository under `$GITHUB_WORKSPACE`, so your workflow can access it.
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ describe('Test fetchDepth and fetchTags options', () => {
|
|||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'--filter=filterValue',
|
||||
|
|
@ -248,6 +249,7 @@ describe('Test fetchDepth and fetchTags options', () => {
|
|||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'--filter=filterValue',
|
||||
|
|
@ -364,6 +366,7 @@ describe('Test fetchDepth and fetchTags options', () => {
|
|||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'--progress',
|
||||
|
|
@ -376,3 +379,225 @@ describe('Test fetchDepth and fetchTags options', () => {
|
|||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Test git 2.48 tag fetching behavior', () => {
|
||||
beforeEach(async () => {
|
||||
jest.spyOn(fshelper, 'fileExistsSync').mockImplementation(jest.fn())
|
||||
jest.spyOn(fshelper, 'directoryExistsSync').mockImplementation(jest.fn())
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('should perform separate tag fetch for git 2.48 when fetchTags is true', async () => {
|
||||
mockExec.mockImplementation((path, args, options) => {
|
||||
if (args.includes('version')) {
|
||||
options.listeners.stdout(Buffer.from('2.48.1'))
|
||||
}
|
||||
return 0
|
||||
})
|
||||
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
|
||||
|
||||
const workingDirectory = 'test'
|
||||
const lfs = false
|
||||
const doSparseCheckout = false
|
||||
git = await commandManager.createCommandManager(
|
||||
workingDirectory,
|
||||
lfs,
|
||||
doSparseCheckout
|
||||
)
|
||||
|
||||
const refSpec = ['refspec1']
|
||||
const options = {
|
||||
fetchTags: true
|
||||
}
|
||||
|
||||
await git.fetch(refSpec, options)
|
||||
|
||||
// First call: main fetch with --no-tags
|
||||
expect(mockExec).toHaveBeenNthCalledWith(
|
||||
2, // First call is version check
|
||||
expect.any(String),
|
||||
[
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--no-tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'origin',
|
||||
'refspec1'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
|
||||
// Second call: separate tag fetch
|
||||
expect(mockExec).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
expect.any(String),
|
||||
[
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--tags',
|
||||
'--prune',
|
||||
'origin'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
|
||||
expect(mockExec).toHaveBeenCalledTimes(3) // version + main fetch + tag fetch
|
||||
})
|
||||
|
||||
it('should perform separate tag fetch with progress for git 2.48', async () => {
|
||||
mockExec.mockImplementation((path, args, options) => {
|
||||
if (args.includes('version')) {
|
||||
options.listeners.stdout(Buffer.from('2.48.0'))
|
||||
}
|
||||
return 0
|
||||
})
|
||||
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
|
||||
|
||||
const workingDirectory = 'test'
|
||||
const lfs = false
|
||||
const doSparseCheckout = false
|
||||
git = await commandManager.createCommandManager(
|
||||
workingDirectory,
|
||||
lfs,
|
||||
doSparseCheckout
|
||||
)
|
||||
|
||||
const refSpec = ['refspec1']
|
||||
const options = {
|
||||
fetchTags: true,
|
||||
showProgress: true
|
||||
}
|
||||
|
||||
await git.fetch(refSpec, options)
|
||||
|
||||
// Main fetch with --no-tags and --progress
|
||||
expect(mockExec).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.any(String),
|
||||
[
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--no-tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'--progress',
|
||||
'origin',
|
||||
'refspec1'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
|
||||
// Separate tag fetch with --progress
|
||||
expect(mockExec).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
expect.any(String),
|
||||
[
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--tags',
|
||||
'--prune',
|
||||
'--progress',
|
||||
'origin'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
})
|
||||
|
||||
it('should NOT perform separate tag fetch for git 2.48 when fetchTags is false', async () => {
|
||||
mockExec.mockImplementation((path, args, options) => {
|
||||
if (args.includes('version')) {
|
||||
options.listeners.stdout(Buffer.from('2.48.1'))
|
||||
}
|
||||
return 0
|
||||
})
|
||||
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
|
||||
|
||||
const workingDirectory = 'test'
|
||||
const lfs = false
|
||||
const doSparseCheckout = false
|
||||
git = await commandManager.createCommandManager(
|
||||
workingDirectory,
|
||||
lfs,
|
||||
doSparseCheckout
|
||||
)
|
||||
|
||||
const refSpec = ['refspec1']
|
||||
const options = {
|
||||
fetchTags: false
|
||||
}
|
||||
|
||||
await git.fetch(refSpec, options)
|
||||
|
||||
// Only one fetch call with --no-tags
|
||||
expect(mockExec).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.any(String),
|
||||
[
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--no-tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'origin',
|
||||
'refspec1'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
|
||||
expect(mockExec).toHaveBeenCalledTimes(2) // version + single fetch only
|
||||
})
|
||||
|
||||
it('should use normal behavior for non-2.48 git versions', async () => {
|
||||
mockExec.mockImplementation((path, args, options) => {
|
||||
if (args.includes('version')) {
|
||||
options.listeners.stdout(Buffer.from('2.47.0'))
|
||||
}
|
||||
return 0
|
||||
})
|
||||
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
|
||||
|
||||
const workingDirectory = 'test'
|
||||
const lfs = false
|
||||
const doSparseCheckout = false
|
||||
git = await commandManager.createCommandManager(
|
||||
workingDirectory,
|
||||
lfs,
|
||||
doSparseCheckout
|
||||
)
|
||||
|
||||
const refSpec = ['refspec1']
|
||||
const options = {
|
||||
fetchTags: true
|
||||
}
|
||||
|
||||
await git.fetch(refSpec, options)
|
||||
|
||||
// Single fetch with --tags
|
||||
expect(mockExec).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.any(String),
|
||||
[
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--tags',
|
||||
'--prune',
|
||||
'--no-recurse-submodules',
|
||||
'origin',
|
||||
'refspec1'
|
||||
],
|
||||
expect.any(Object)
|
||||
)
|
||||
|
||||
expect(mockExec).toHaveBeenCalledTimes(2) // version + single fetch only
|
||||
})
|
||||
})
|
||||
|
|
|
|||
4
dist/index.js
vendored
4
dist/index.js
vendored
|
|
@ -825,8 +825,8 @@ class GitCommandManager {
|
|||
fetch(refSpec, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = ['-c', 'protocol.version=2', 'fetch'];
|
||||
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !options.fetchTags) {
|
||||
args.push('--no-tags');
|
||||
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
|
||||
args.push(options.fetchTags ? '--tags' : '--no-tags');
|
||||
}
|
||||
args.push('--prune', '--no-recurse-submodules');
|
||||
if (options.showProgress) {
|
||||
|
|
|
|||
|
|
@ -285,8 +285,12 @@ class GitCommandManager {
|
|||
}
|
||||
): Promise<void> {
|
||||
const args = ['-c', 'protocol.version=2', 'fetch']
|
||||
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !options.fetchTags) {
|
||||
args.push('--no-tags')
|
||||
const hasTagsRefSpec = refSpec.some(x => x === refHelper.tagsRefSpec)
|
||||
const needsSeparateTagFetch = this.gitVersion.toString().startsWith('2.48') && options.fetchTags && !hasTagsRefSpec
|
||||
|
||||
if (!hasTagsRefSpec) {
|
||||
// For git 2.48, skip --tags here if we need separate fetch
|
||||
args.push(needsSeparateTagFetch || !options.fetchTags ? '--no-tags' : '--tags')
|
||||
}
|
||||
|
||||
args.push('--prune', '--no-recurse-submodules')
|
||||
|
|
@ -317,6 +321,19 @@ class GitCommandManager {
|
|||
await retryHelper.execute(async () => {
|
||||
await that.execGit(args)
|
||||
})
|
||||
|
||||
// Separate tag fetch for git 2.48
|
||||
if (needsSeparateTagFetch) {
|
||||
const tagArgs = ['-c', 'protocol.version=2', 'fetch', '--tags', '--prune']
|
||||
if (options.showProgress) {
|
||||
tagArgs.push('--progress')
|
||||
}
|
||||
tagArgs.push('origin')
|
||||
|
||||
await retryHelper.execute(async () => {
|
||||
await that.execGit(tagArgs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async getDefaultBranch(repositoryUrl: string): Promise<string> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue