Skip to content

Commit 02e39cf

Browse files
Add option to fetch tags even if fetch-depth > 0
1 parent afe4af0 commit 02e39cf

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
@@ -93,6 +93,10 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
9393
# Default: 1
9494
fetch-depth: ''
9595

96+
# Whether to fetch tags, even if fetch-depth > 0.
97+
# Default: false
98+
fetch-tags: ''
99+
96100
# Whether to download Git-LFS files
97101
# Default: false
98102
lfs: ''

__test__/git-auth-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ async function setup(testName: string): Promise<void> {
760760
clean: true,
761761
commit: '',
762762
fetchDepth: 1,
763+
fetchTags: false,
763764
lfs: false,
764765
submodules: false,
765766
nestedSubmodules: false,

__test__/input-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('input-helper tests', () => {
7575
expect(settings.commit).toBeTruthy()
7676
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
7777
expect(settings.fetchDepth).toBe(1)
78+
expect(settings.fetchTags).toBe(false)
7879
expect(settings.lfs).toBe(false)
7980
expect(settings.ref).toBe('refs/heads/some-ref')
8081
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
@@ -5804,10 +5804,10 @@ class GitCommandManager {
58045804
return output.exitCode === 0;
58055805
});
58065806
}
5807-
fetch(refSpec, fetchDepth) {
5807+
fetch(refSpec, fetchDepth, fetchTags) {
58085808
return __awaiter(this, void 0, void 0, function* () {
58095809
const args = ['-c', 'protocol.version=2', 'fetch'];
5810-
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
5810+
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !fetchTags) {
58115811
args.push('--no-tags');
58125812
}
58135813
args.push('--prune', '--progress', '--no-recurse-submodules');
@@ -5885,8 +5885,8 @@ class GitCommandManager {
58855885
}
58865886
log1(format) {
58875887
return __awaiter(this, void 0, void 0, function* () {
5888-
var args = format ? ['log', '-1', format] : ['log', '-1'];
5889-
var silent = format ? false : true;
5888+
const args = format ? ['log', '-1', format] : ['log', '-1'];
5889+
const silent = format ? false : true;
58905890
const output = yield this.execGit(args, false, silent);
58915891
return output.stdout;
58925892
});
@@ -6226,7 +6226,7 @@ function getSource(settings) {
62266226
}
62276227
else {
62286228
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
6229-
yield git.fetch(refSpec, settings.fetchDepth);
6229+
yield git.fetch(refSpec, settings.fetchDepth, settings.fetchTags);
62306230
}
62316231
core.endGroup();
62326232
// Checkout info
@@ -14572,6 +14572,10 @@ function getInputs() {
1457214572
result.fetchDepth = 0;
1457314573
}
1457414574
core.debug(`fetch depth = ${result.fetchDepth}`);
14575+
// Fetch tags
14576+
result.fetchTags =
14577+
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE';
14578+
core.debug(`fetch tags = ${result.fetchTags}`);
1457514579
// LFS
1457614580
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1457714581
core.debug(`lfs = ${result.lfs}`);

src/git-command-manager.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export interface IGitCommandManager {
2424
globalConfig?: boolean
2525
): Promise<void>
2626
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
27-
fetch(refSpec: string[], fetchDepth?: number): Promise<void>
27+
fetch(
28+
refSpec: string[],
29+
fetchDepth?: number,
30+
fetchTags?: boolean
31+
): Promise<void>
2832
getDefaultBranch(repositoryUrl: string): Promise<string>
2933
getWorkingDirectory(): string
3034
init(): Promise<void>
@@ -168,9 +172,14 @@ class GitCommandManager {
168172
return output.exitCode === 0
169173
}
170174

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

@@ -255,8 +264,8 @@ class GitCommandManager {
255264
}
256265

257266
async log1(format?: string): Promise<string> {
258-
var args = format ? ['log', '-1', format] : ['log', '-1']
259-
var silent = format ? false : true
267+
const args = format ? ['log', '-1', format] : ['log', '-1']
268+
const silent = format ? false : true
260269
const output = await this.execGit(args, false, silent)
261270
return output.stdout
262271
}

src/git-source-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
141141
}
142142
} else {
143143
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
144-
await git.fetch(refSpec, settings.fetchDepth)
144+
await git.fetch(refSpec, settings.fetchDepth, settings.fetchTags)
145145
}
146146
core.endGroup()
147147

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
@@ -88,6 +88,11 @@ export function getInputs(): IGitSourceSettings {
8888
}
8989
core.debug(`fetch depth = ${result.fetchDepth}`)
9090

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy