actions / checkout

Action for checking out a repo
https://github.com/features/actions
MIT License
5.79k stars 1.7k forks source link

bug: `checkout` will leak submodules from the previous branch on self-hosted runners #1855

Open milesvant opened 1 month ago

milesvant commented 1 month ago

The clean argument (which executes git clean -ffdx && git reset --hard HEAD) is insufficient for cleaning up a previous branch's submodule state. git clean will not remove the submodule's folder since it is checked in, meaning that it remains in the repo as untracked state when you checkout a different branch which does not contain the submodule. I resolved this by cleaning after checkout as well:

      - uses: actions/checkout@v4

      # Because each invocation is not in an isolated environment, we need to force clean
      # AFTER checkout to remove any stale submodule state from a previous branch's run.
      - name: Clean git state
        run: git clean -ffdx
AceCoderLaura commented 2 weeks ago

There's an outdated branch you can use to fix this (#628) but would be nice to get this fixed in main.