Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ref and fetch-depth: 0 assumes that ref is either branch or tag #1515

Closed
jbergstroem opened this issue Oct 17, 2023 · 3 comments
Closed

Comments

@jbergstroem
Copy link

I'm passing a commit to ref instead of a branch or tag. When using fetch-depth: 0 in conjunction to this, I run into a checkout error (output from job):

/usr/bin/git branch --list --remote origin/cfe42d2a
/usr/bin/git tag --list cfe42d2a
Error: A branch or tag with the name 'cfe42d2a' could not be found

Debug info

  • Download action repository 'actions/checkout@v4' (SHA:b4ffde65f46336ab88eb53be808477a3936bae11)
  • This job is invoked via workflow_call where an input is what git ref to check out.
  • Job:
    e2e-test:
      name: Run E2E tests
      timeout-minutes: 20
      runs-on: ubuntu-22.04
      steps:
        - name: Checkout
          uses: actions/checkout@v4
          with:
            fetch-depth: 0
            ref: ${{ inputs.ref != '' && inputs.ref || github.sha }}

..looking at the code, I can't help but feeling that the case is not covered?

// SHA only
if (!ref) {
result.ref = commit
}
// refs/heads/
else if (upperRef.startsWith('REFS/HEADS/')) {
const branch = ref.substring('refs/heads/'.length)
result.ref = branch
result.startPoint = `refs/remotes/origin/${branch}`
}
// refs/pull/
else if (upperRef.startsWith('REFS/PULL/')) {
const branch = ref.substring('refs/pull/'.length)
result.ref = `refs/remotes/pull/${branch}`
}
// refs/tags/
else if (upperRef.startsWith('REFS/')) {
result.ref = ref
}
// Unqualified ref, check for a matching branch or tag
else {
if (await git.branchExists(true, `origin/${ref}`)) {
result.ref = ref
result.startPoint = `refs/remotes/origin/${ref}`
} else if (await git.tagExists(`${ref}`)) {
result.ref = `refs/tags/${ref}`
} else {
throw new Error(
`A branch or tag with the name '${ref}' could not be found`
)
}
}

..finally, if I skip passing fetch-depth: 0, I run into this issue: #1313

@jlongo-encora
Copy link

Probably this is the cause of your issue: #265

@jbergstroem
Copy link
Author

Probably this is the cause of your issue: #265

Yeah I think you're right. Will test.

@jbergstroem
Copy link
Author

Duplicate of #265.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@jbergstroem @jlongo-encora and others