Skip to content

Commit 655f7fa

Browse files
Add option to fetch tags even if fetch-depth > 0
1 parent 2541b12 commit 655f7fa

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
@@ -80,6 +80,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
8080
# Default: 1
8181
fetch-depth: ''
8282

83+
# Whether to fetch tags, even if fetch-depth > 0.
84+
# Default: false
85+
fetch-tags: ''
86+
8387
# Whether to download Git-LFS files
8488
# Default: false
8589
lfs: ''

__test__/git-auth-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ async function setup(testName: string): Promise<void> {
766766
clean: true,
767767
commit: '',
768768
fetchDepth: 1,
769+
fetchTags: false,
769770
lfs: false,
770771
submodules: false,
771772
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
@@ -6984,10 +6984,10 @@ class GitCommandManager {
69846984
return output.exitCode === 0;
69856985
});
69866986
}
6987-
fetch(refSpec, fetchDepth) {
6987+
fetch(refSpec, fetchDepth, fetchTags) {
69886988
return __awaiter(this, void 0, void 0, function* () {
69896989
const args = ['-c', 'protocol.version=2', 'fetch'];
6990-
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
6990+
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !fetchTags) {
69916991
args.push('--no-tags');
69926992
}
69936993
args.push('--prune', '--progress', '--no-recurse-submodules');
@@ -7065,8 +7065,8 @@ class GitCommandManager {
70657065
}
70667066
log1(format) {
70677067
return __awaiter(this, void 0, void 0, function* () {
7068-
var args = format ? ['log', '-1', format] : ['log', '-1'];
7069-
var silent = format ? false : true;
7068+
const args = format ? ['log', '-1', format] : ['log', '-1'];
7069+
const silent = format ? false : true;
70707070
const output = yield this.execGit(args, false, silent);
70717071
return output.stdout;
70727072
});
@@ -7438,7 +7438,7 @@ function getSource(settings) {
74387438
}
74397439
else {
74407440
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
7441-
yield git.fetch(refSpec, settings.fetchDepth);
7441+
yield git.fetch(refSpec, settings.fetchDepth, settings.fetchTags);
74427442
}
74437443
core.endGroup();
74447444
// Checkout info
@@ -17299,6 +17299,10 @@ function getInputs() {
1729917299
result.fetchDepth = 0;
1730017300
}
1730117301
core.debug(`fetch depth = ${result.fetchDepth}`);
17302+
// Fetch tags
17303+
result.fetchTags =
17304+
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE';
17305+
core.debug(`fetch tags = ${result.fetchTags}`);
1730217306
// LFS
1730317307
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1730417308
core.debug(`lfs = ${result.lfs}`);

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>
@@ -170,9 +174,14 @@ class GitCommandManager {
170174
return output.exitCode === 0
171175
}
172176

173-
async fetch(refSpec: string[], fetchDepth?: number): Promise<void> {
177+
async fetch(
178+
refSpec: string[],
179+
fetchDepth?: number,
180+
fetchTags?: boolean
181+
): Promise<void> {
174182
const args = ['-c', 'protocol.version=2', 'fetch']
175-
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
183+
184+
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !fetchTags) {
176185
args.push('--no-tags')
177186
}
178187

@@ -257,8 +266,8 @@ class GitCommandManager {
257266
}
258267

259268
async log1(format?: string): Promise<string> {
260-
var args = format ? ['log', '-1', format] : ['log', '-1']
261-
var silent = format ? false : true
269+
const args = format ? ['log', '-1', format] : ['log', '-1']
270+
const silent = format ? false : true
262271
const output = await this.execGit(args, false, silent)
263272
return output.stdout
264273
}

src/git-source-provider.ts

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

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)