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
2.07k stars 231 forks source link

error: The following untracked working tree files would be overwritten by checkout #275

Closed aLosada7 closed 1 year ago

aLosada7 commented 1 year ago

git-auto-commit Version

v4.16.0

Machine Type

Ubuntu (eg. ubuntu-latest)

Bug description

I am getting the following error:

error: The following untracked working tree files would be overwritten by checkout:
[30](https://github.com/aLosada7/edene/actions/runs/3778321913/jobs/6422695658#step:5:31)
    CHANGELOG.md
[31](https://github.com/aLosada7/edene/actions/runs/3778321913/jobs/6422695658#step:5:32)
Please move or remove them before you switch branches.

Some help will be appreciated.

Steps to reproduce

You can find the logs here: https://github.com/aLosada7/edene/actions/runs/3778321913/jobs/6422695658

Tried solutions

No response

Example Workflow

name: 'Edene Changelog CI'

on:
    push:
        tags:
            - '*'

jobs:
    publish-changelog:
        runs-on: ubuntu-latest

        steps:
            - name: Checkout Code
              uses: actions/checkout@v2

            - name: Update CHANGELOG
              id: changelog
              uses: requarks/changelog-action@v1
              with:
                  token: ${{ github.token }}
                  tag: ${{ github.ref_name }}

            - name: Create Release
              uses: ncipollo/release-action@v1
              with:
                  allowUpdates: true
                  draft: false
                  name: ${{ github.ref_name }}
                  body: ${{ steps.changelog.outputs.changes }}
                  token: ${{ github.token }}

            - name: Commit CHANGELOG.md
              uses: stefanzweifel/git-auto-commit-action@v4
              with:
                  branch: main
                  commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }}'
                  file_pattern: CHANGELOG.md

Relevant log output

No response

stefanzweifel commented 1 year ago

You workflow checks out the repository in a "detached HEAD" state. This means that Actions doesn't checkout a branch but rather a single commit.

https://github.com/aLosada7/edene/actions/runs/3778321913/jobs/6422695658#step:2:426

This leads to a problem when git-auto-commit tries to internally switch to the main-branch.

You can fix this by passing the branch name to be checked out to actions/checkout-Action (more).

            - name: Checkout Code
              uses: actions/checkout@v2
+             with:
+               ref: main