-
Notifications
You must be signed in to change notification settings - Fork 24
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
Push of formatted code fails with "fatal: You are not currently on a branch." #11
Comments
Hi, When you run a workflow on a
From this Stackoverflow page, we learn that To sum it up, this means that you are checked out on a commit that does not belong to any branch yet. Now, if you want to commit something on a jobs:
formatting:
runs-on: ubuntu-latest
steps:
- if: github.event_name != 'pull_request'
uses: actions/checkout@v2
- if: github.event_name == 'pull_request'
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }} The thing you'll have to take care of is the case where the head branch does not belong to the same repository: then you will probably not have the permission to commit on it. In this case you could just skip the commit. I don't know exactly which scenario you want to implement, but I believe the simplest way to solve your issue is to skip the commit on |
@axel-op Awesome, thanks for the tip, it works! At least with a PR from a branch on the same repo. Here's the full config for anyone with a similar problem:
We'll have to test to see if the commit works with PRs from forked repos, and if not we'll change the config so it runs on push on main branch instead. I'd prefer to keep it in PRs if possible so it's squashed as part of the PR and we don't clutter the main branch with formatting commits, but it would still work. Thanks again for the great plugin! |
* ci: Automatically format code * Make sure we're on a branch for pull requests See axel-op/googlejavaformat-action#11 (comment) * Google Java Format https://github.com/google/google-java-format Co-authored-by: github-actions <>
Hello @daltonfury42, The commit is from a different repository. Try this: formatting:
runs-on: ubuntu-latest
steps:
- if: github.event_name != 'pull_request'
uses: actions/checkout@v2
- if: github.event_name == 'pull_request'
uses: actions/checkout@v2
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }} |
First off, great plugin!
I'm trying to apply it in a new PR here:
https://github.com/MobilityData/gtfs-validator/pull/616/checks?check_run_id=1743823100
It's a really basic config inside an existing workflow file:
However, it's failing with the following:
Am I missing something simple here?
The text was updated successfully, but these errors were encountered: