@@ -653,7 +653,6 @@ const fs = __importStar(__nccwpck_require__(7147));
653653const fshelper = __importStar(__nccwpck_require__(7219));
654654const io = __importStar(__nccwpck_require__(7436));
655655const path = __importStar(__nccwpck_require__(1017));
656- const refHelper = __importStar(__nccwpck_require__(8601));
657656const regexpHelper = __importStar(__nccwpck_require__(3120));
658657const retryHelper = __importStar(__nccwpck_require__(2155));
659658const git_version_1 = __nccwpck_require__(3142);
@@ -831,9 +830,9 @@ class GitCommandManager {
831830 fetch(refSpec, options) {
832831 return __awaiter(this, void 0, void 0, function* () {
833832 const args = ['-c', 'protocol.version=2', 'fetch'];
834- if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !options.fetchTags) {
835- args.push('--no-tags');
836- }
833+ // Always use --no-tags for explicit control over tag fetching
834+ // Tags are fetched explicitly via refspec when needed
835+ args.push('--no-tags');
837836 args.push('--prune', '--no-recurse-submodules');
838837 if (options.showProgress) {
839838 args.push('--progress');
@@ -1539,13 +1538,26 @@ function getSource(settings) {
15391538 if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) {
15401539 refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
15411540 yield git.fetch(refSpec, fetchOptions);
1541+ // Verify the ref now matches. For branches, the targeted fetch above brings
1542+ // in the specific commit. For tags (fetched by ref), this will fail if
1543+ // the tag was moved after the workflow was triggered.
1544+ if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) {
1545+ throw new Error(`The ref '${settings.ref}' does not point to the expected commit '${settings.commit}'. ` +
1546+ `The ref may have been updated after the workflow was triggered.`);
1547+ }
15421548 }
15431549 }
15441550 else {
15451551 fetchOptions.fetchDepth = settings.fetchDepth;
1546- fetchOptions.fetchTags = settings.fetchTags;
1547- const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
1552+ const refSpec = refHelper.getRefSpec(settings.ref, settings.commit, settings.fetchTags);
15481553 yield git.fetch(refSpec, fetchOptions);
1554+ // For tags, verify the ref still points to the expected commit.
1555+ // Tags are fetched by ref (not commit), so if a tag was moved after the
1556+ // workflow was triggered, we would silently check out the wrong commit.
1557+ if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) {
1558+ throw new Error(`The ref '${settings.ref}' does not point to the expected commit '${settings.commit}'. ` +
1559+ `The ref may have been updated after the workflow was triggered.`);
1560+ }
15491561 }
15501562 core.endGroup();
15511563 // Checkout info
@@ -2284,53 +2296,67 @@ function getRefSpecForAllHistory(ref, commit) {
22842296 }
22852297 return result;
22862298}
2287- function getRefSpec(ref, commit) {
2299+ function getRefSpec(ref, commit, fetchTags ) {
22882300 if (!ref && !commit) {
22892301 throw new Error('Args ref and commit cannot both be empty');
22902302 }
22912303 const upperRef = (ref || '').toUpperCase();
2304+ const result = [];
2305+ // When fetchTags is true, always include the tags refspec
2306+ if (fetchTags) {
2307+ result.push(exports.tagsRefSpec);
2308+ }
22922309 // SHA
22932310 if (commit) {
22942311 // refs/heads
22952312 if (upperRef.startsWith('REFS/HEADS/')) {
22962313 const branch = ref.substring('refs/heads/'.length);
2297- return [ `+${commit}:refs/remotes/origin/${branch}`] ;
2314+ result.push( `+${commit}:refs/remotes/origin/${branch}`) ;
22982315 }
22992316 // refs/pull/
23002317 else if (upperRef.startsWith('REFS/PULL/')) {
23012318 const branch = ref.substring('refs/pull/'.length);
2302- return [ `+${commit}:refs/remotes/pull/${branch}`] ;
2319+ result.push( `+${commit}:refs/remotes/pull/${branch}`) ;
23032320 }
23042321 // refs/tags/
23052322 else if (upperRef.startsWith('REFS/TAGS/')) {
2306- return [`+${commit}:${ref}`];
2323+ if (!fetchTags) {
2324+ result.push(`+${ref}:${ref}`);
2325+ }
23072326 }
23082327 // Otherwise no destination ref
23092328 else {
2310- return [ commit] ;
2329+ result.push( commit) ;
23112330 }
23122331 }
23132332 // Unqualified ref, check for a matching branch or tag
23142333 else if (!upperRef.startsWith('REFS/')) {
2315- return [
2316- `+refs/heads/${ref}*:refs/remotes/origin/${ref}*`,
2317- `+refs/tags/${ref}*:refs/tags/${ref}*`
2318- ];
2334+ result.push(`+refs/heads/${ref}*:refs/remotes/origin/${ref}*`);
2335+ if (!fetchTags) {
2336+ result.push( `+refs/tags/${ref}*:refs/tags/${ref}*`);
2337+ }
23192338 }
23202339 // refs/heads/
23212340 else if (upperRef.startsWith('REFS/HEADS/')) {
23222341 const branch = ref.substring('refs/heads/'.length);
2323- return [ `+${ref}:refs/remotes/origin/${branch}`] ;
2342+ result.push( `+${ref}:refs/remotes/origin/${branch}`) ;
23242343 }
23252344 // refs/pull/
23262345 else if (upperRef.startsWith('REFS/PULL/')) {
23272346 const branch = ref.substring('refs/pull/'.length);
2328- return [ `+${ref}:refs/remotes/pull/${branch}`] ;
2347+ result.push( `+${ref}:refs/remotes/pull/${branch}`) ;
23292348 }
23302349 // refs/tags/
2350+ else if (upperRef.startsWith('REFS/TAGS/')) {
2351+ if (!fetchTags) {
2352+ result.push(`+${ref}:${ref}`);
2353+ }
2354+ }
2355+ // Other refs
23312356 else {
2332- return [ `+${ref}:${ref}`] ;
2357+ result.push( `+${ref}:${ref}`) ;
23332358 }
2359+ return result;
23342360}
23352361/**
23362362 * Tests whether the initial fetch created the ref at the expected commit
@@ -2366,7 +2392,9 @@ function testRef(git, ref, commit) {
23662392 // refs/tags/
23672393 else if (upperRef.startsWith('REFS/TAGS/')) {
23682394 const tagName = ref.substring('refs/tags/'.length);
2369- return ((yield git.tagExists(tagName)) && commit === (yield git.revParse(ref)));
2395+ // Use ^{commit} to dereference annotated tags to their underlying commit
2396+ return ((yield git.tagExists(tagName)) &&
2397+ commit === (yield git.revParse(`${ref}^{commit}`)));
23702398 }
23712399 // Unexpected
23722400 else {
0 commit comments