Skip to content

Commit b9d6ac4

Browse files
Add option to fetch tags even if fetch-depth > 0
1 parent ac59398 commit b9d6ac4

File tree

9 files changed

+43
-11
lines changed

9 files changed

+43
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
7878
# Default: 1
7979
fetch-depth: ''
8080

81+
# Whether to fetch tags, even if fetch-depth > 0.
82+
# Default: false
83+
fetch-tags: ''
84+
8185
# Whether to download Git-LFS files
8286
# Default: false
8387
lfs: ''

__test__/git-auth-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ async function setup(testName: string): Promise<void> {
798798
clean: true,
799799
commit: '',
800800
fetchDepth: 1,
801+
fetchTags: false,
801802
lfs: false,
802803
submodules: false,
803804
nestedSubmodules: false,

__test__/input-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ describe('input-helper tests', () => {
8080
expect(settings.commit).toBeTruthy()
8181
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
8282
expect(settings.fetchDepth).toBe(1)
83+
expect(settings.fetchTags).toBe(false)
8384
expect(settings.lfs).toBe(false)
8485
expect(settings.ref).toBe('refs/heads/some-ref')
8586
expect(settings.repositoryName).toBe('some-repo')

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ inputs:
5656
fetch-depth:
5757
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
5858
default: 1
59+
fetch-tags:
60+
description: 'Whether to fetch tags, even if fetch-depth > 0.'
61+
default: false
5962
lfs:
6063
description: 'Whether to download Git-LFS files'
6164
default: false

dist/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7533,10 +7533,10 @@ class GitCommandManager {
75337533
return output.exitCode === 0;
75347534
});
75357535
}
7536-
fetch(refSpec, fetchDepth) {
7536+
fetch(refSpec, fetchDepth, fetchTags) {
75377537
return __awaiter(this, void 0, void 0, function* () {
75387538
const args = ['-c', 'protocol.version=2', 'fetch'];
7539-
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
7539+
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !fetchTags) {
75407540
args.push('--no-tags');
75417541
}
75427542
args.push('--prune', '--progress', '--no-recurse-submodules');
@@ -7614,8 +7614,8 @@ class GitCommandManager {
76147614
}
76157615
log1(format) {
76167616
return __awaiter(this, void 0, void 0, function* () {
7617-
var args = format ? ['log', '-1', format] : ['log', '-1'];
7618-
var silent = format ? false : true;
7617+
const args = format ? ['log', '-1', format] : ['log', '-1'];
7618+
const silent = format ? false : true;
76197619
const output = yield this.execGit(args, false, silent);
76207620
return output.stdout;
76217621
});
@@ -18521,6 +18521,10 @@ function getInputs() {
1852118521
result.fetchDepth = 0;
1852218522
}
1852318523
core.debug(`fetch depth = ${result.fetchDepth}`);
18524+
// Fetch tags
18525+
result.fetchTags =
18526+
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE';
18527+
core.debug(`fetch tags = ${result.fetchTags}`);
1852418528
// LFS
1852518529
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1852618530
core.debug(`lfs = ${result.lfs}`);
@@ -31981,7 +31985,7 @@ function getSource(settings) {
3198131985
}
3198231986
else {
3198331987
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
31984-
yield git.fetch(refSpec, settings.fetchDepth);
31988+
yield git.fetch(refSpec, settings.fetchDepth, settings.fetchTags);
3198531989
}
3198631990
core.endGroup();
3198731991
// Checkout info

src/git-command-manager.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export interface IGitCommandManager {
2525
add?: boolean
2626
): Promise<void>
2727
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
28-
fetch(refSpec: string[], fetchDepth?: number): Promise<void>
28+
fetch(
29+
refSpec: string[],
30+
fetchDepth?: number,
31+
fetchTags?: boolean
32+
): Promise<void>
2933
getDefaultBranch(repositoryUrl: string): Promise<string>
3034
getWorkingDirectory(): string
3135
init(): Promise<void>
@@ -201,9 +205,14 @@ class GitCommandManager {
201205
return output.exitCode === 0
202206
}
203207

204-
async fetch(refSpec: string[], fetchDepth?: number): Promise<void> {
208+
async fetch(
209+
refSpec: string[],
210+
fetchDepth?: number,
211+
fetchTags?: boolean
212+
): Promise<void> {
205213
const args = ['-c', 'protocol.version=2', 'fetch']
206-
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
214+
215+
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !fetchTags) {
207216
args.push('--no-tags')
208217
}
209218

@@ -288,8 +297,8 @@ class GitCommandManager {
288297
}
289298

290299
async log1(format?: string): Promise<string> {
291-
var args = format ? ['log', '-1', format] : ['log', '-1']
292-
var silent = format ? false : true
300+
const args = format ? ['log', '-1', format] : ['log', '-1']
301+
const silent = format ? false : true
293302
const output = await this.execGit(args, false, silent)
294303
return output.stdout
295304
}

src/git-source-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
169169
}
170170
} else {
171171
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
172-
await git.fetch(refSpec, settings.fetchDepth)
172+
await git.fetch(refSpec, settings.fetchDepth, settings.fetchTags)
173173
}
174174
core.endGroup()
175175

src/git-source-settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export interface IGitSourceSettings {
3434
*/
3535
fetchDepth: number
3636

37+
/**
38+
* Fetch tags, even if fetchDepth > 0 (default: false)
39+
*/
40+
fetchTags: boolean
41+
3742
/**
3843
* Indicates whether to fetch LFS objects
3944
*/

src/input-helper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export async function getInputs(): Promise<IGitSourceSettings> {
8989
}
9090
core.debug(`fetch depth = ${result.fetchDepth}`)
9191

92+
// Fetch tags
93+
result.fetchTags =
94+
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE'
95+
core.debug(`fetch tags = ${result.fetchTags}`)
96+
9297
// LFS
9398
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
9499
core.debug(`lfs = ${result.lfs}`)

0 commit comments

Comments
 (0)