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

ref of "HEAD" does not work #969

Open
ljharb opened this issue Oct 17, 2022 · 7 comments
Open

ref of "HEAD" does not work #969

ljharb opened this issue Oct 17, 2022 · 7 comments

Comments

@ljharb
Copy link

ljharb commented Oct 17, 2022

Related to #910, I'd like to be able to default the ref to HEAD so i don't have to hardcode main or master or whatever in a reusable workflow, but instead i get:

  Determining the checkout info
  /usr/bin/git branch --list --remote origin/HEAD
  /usr/bin/git tag --list HEAD
  Error: A branch or tag with the name 'HEAD' could not be found
@rainui28
Copy link

rainui28 commented Jan 18, 2023

Same issue happens when using a commit SHA despite the fact that the README.md specifies

    # The branch, tag or SHA to checkout. When checking out the repository that
    # triggered a workflow, this defaults to the reference or SHA for that event.
    # Otherwise, uses the default branch.
    ref: ''

@ljharb
Copy link
Author

ljharb commented Nov 2, 2023

For "HEAD", seems like I'd need to make the changes here:

// 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`
)
}
}

For the sha, it seems like the logic that handles that is here:

result.ref = github.context.ref
result.commit = github.context.sha

cc @ericsciple; would i need to special-case "HEAD" to look up .git/refs/remotes/origin/HEAD and parse out its ref value and split out what's after refs/remotes/origin/? or is there a cleaner/better way to do it?

@ljharb
Copy link
Author

ljharb commented Nov 28, 2023

cc @cory-miller?

@mihaigalos
Copy link

Seems the HEAD file doesn't exist in the following hierarchy when using the action:

['./.git/refs/remotes/origin/feat', './.git/refs/remotes/origin/fix', './.git/refs/remotes/origin/main']

I would expect a file called .git/refs/remotes/origin/HEAD which contains ref: refs/remotes/origin/main for main.

@ljharb
Copy link
Author

ljharb commented Feb 27, 2024

cc @jww3?

@AlexAtkinson
Copy link

Occasionally I'm reminded of this. Today is one of those occasions. It would be nice if HEAD was included in the GHA environment and showed up when running git show-ref. There's a great deal of script that references it -- ideally, these assets wouldn't have to be adjusted to run in GHA. Thanks.

@saagarjha
Copy link

Maybe the best strategy here would be to send in a PR and see what they have to say?

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

5 participants