stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.97k stars 226 forks source link

Create a branch if it doesn't exist #202

Closed palewire closed 2 years ago

palewire commented 2 years ago

I'd like to be able to list branch names not yet in the repo and have them work out of the box. Right now if I do that I get an error at the checkout step.

Would you be open to a test that would look if the branch already exists before checking out, and then creates a new branch with checkout -b if it doesn't?

stefanzweifel commented 2 years ago

@palewire Sounds like a good idea. Feel free to send a PR with such a test.

I already tried this in #140, but broke the Action for others in this step. See comments in #142.

Or feel free to share a workflow, where the Action fails. Always great to see, how others use the Action and in what scenarios it fails.

palewire commented 2 years ago

Interesting, what if we kept your basic logic but substituted in this test

git show-ref --verify --quiet refs/heads/<branch-name>

which is the recommended method in this Stack Overflow thread.

stefanzweifel commented 2 years ago

@palewire Will give this a try over the next few days. Have neglected working on this action for a couple of weeks now. Time to get up to speed an close these issues.

Might also hide this "feature" behind an option. Breaking the Action for the now +22k users is not something I want to do. 😄

stefanzweifel commented 2 years ago

@palewire I've prepared something in #203. Test suite and first tests in real applications seem to work fine. Feel free to give this solution a try by updating your workflows like this:

    - uses: stefanzweifel/git-auto-commit-action@master
      with:
        branch: YOUR_BRANCH_NAME_GOES_HERE
        create_branch: true

As the feature is behind a feature flag, I feel confident enough to merge this soonish.

stefanzweifel commented 2 years ago

I've merged the feature to the master branch; but haven't tagged a new version yet. In the past, I've made the mistake and tagged a release too soon and broke Workflows for users. I will tag a new version in the next 1-2 weeks, if no bug reports are coming in.

In the meantime, feel free to use the stefanzweifel/git-auto-commit-action@master as mentioned in the comment above.

Closing this issue now.