0
0
Fork 0
mirror of https://github.com/actions/checkout.git synced 2024-12-22 07:35:47 +02:00

Handle hidden refs (#1774)

Co-authored-by: Chris Gavin <chris@chrisgavin.me>
This commit is contained in:
Orhan Toy 2024-06-12 17:01:40 +02:00 committed by GitHub
parent b80ff79f17
commit b17fe1e4d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View file

@ -67,6 +67,16 @@ describe('ref-helper tests', () => {
expect(checkoutInfo.startPoint).toBeFalsy() expect(checkoutInfo.startPoint).toBeFalsy()
}) })
it('getCheckoutInfo refs/', async () => {
const checkoutInfo = await refHelper.getCheckoutInfo(
git,
'refs/gh/queue/main/pr-123',
commit
)
expect(checkoutInfo.ref).toBe(commit)
expect(checkoutInfo.startPoint).toBeFalsy()
})
it('getCheckoutInfo unqualified branch only', async () => { it('getCheckoutInfo unqualified branch only', async () => {
git.branchExists = jest.fn(async (remote: boolean, pattern: string) => { git.branchExists = jest.fn(async (remote: boolean, pattern: string) => {
return true return true

6
dist/index.js vendored
View file

@ -2000,9 +2000,13 @@ function getCheckoutInfo(git, ref, commit) {
result.ref = `refs/remotes/pull/${branch}`; result.ref = `refs/remotes/pull/${branch}`;
} }
// refs/tags/ // refs/tags/
else if (upperRef.startsWith('REFS/')) { else if (upperRef.startsWith('REFS/TAGS/')) {
result.ref = ref; result.ref = ref;
} }
// refs/
else if (upperRef.startsWith('REFS/') && commit) {
result.ref = commit;
}
// Unqualified ref, check for a matching branch or tag // Unqualified ref, check for a matching branch or tag
else { else {
if (yield git.branchExists(true, `origin/${ref}`)) { if (yield git.branchExists(true, `origin/${ref}`)) {

View file

@ -42,9 +42,13 @@ export async function getCheckoutInfo(
result.ref = `refs/remotes/pull/${branch}` result.ref = `refs/remotes/pull/${branch}`
} }
// refs/tags/ // refs/tags/
else if (upperRef.startsWith('REFS/')) { else if (upperRef.startsWith('REFS/TAGS/')) {
result.ref = ref result.ref = ref
} }
// refs/
else if (upperRef.startsWith('REFS/') && commit) {
result.ref = commit
}
// Unqualified ref, check for a matching branch or tag // Unqualified ref, check for a matching branch or tag
else { else {
if (await git.branchExists(true, `origin/${ref}`)) { if (await git.branchExists(true, `origin/${ref}`)) {