Destructive operation on submodules with
submodule.recurse = true git setting
describe your issue
I added pre-commit to an ansible playbook repository that does extensive usage of git submodules for roles.
I had two submodules with extensive changes:
$ gst On branch master Your branch is ahead of 'origin/master' by 3 commits. (use "git push" to publish your local commits) ... modified: roles/dnscrypt-proxy (modified content) <-- submodule with extensive (non-commited) changes modified: roles/syncthing (modified content) <-- another submodule with extensive (non-commited) changes ...
Upon doing a commit I received an error (check ~/.cache/pre-commit/pre-commit.log section) due to having some problems in my repo and its submodules.
$ gst fatal: not a git repository: roles/matomo/../../.git/modules/roles/matomo
After fixing the problems:
$ rm -rf roles/matomo/ .git/modules/roles/matomo/ $ git submodule update Cloning into '/home/apoc/w/posg-ops/roles/matomo'... Submodule path 'roles/matomo': checked out '######' fatal: could not get a repository handle for submodule 'roles/php' $ rm -rf roles/php/ .git/modules/roles/php $ git submodule update Cloning into '/home/apoc/w/posg-ops/roles/php'... Submodule path 'roles/php': checked out '######'
$ git apply /home/a666/.cache/pre-commit/patch1632709290-1076629
I noticed that my two submodules now had no changes in them...
--- repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-toml - id: check-added-large-files - repo: https://github.com/editorconfig-checker/editorconfig-checker.python rev: 2.3.54 hooks: - id: editorconfig-checker - repo: https://github.com/antonbabenko/pre-commit-terraform rev: v1.51.0 hooks: - id: terraform_validate - id: terraform_fmt - id: checkov - id: terrascan - id: terraform_tfsec
~/.cache/pre-commit/pre-commit.log (if present)
The text was updated successfully, but these errors were encountered:
there's a test in our testsuite which shows this works correctly -- do you have more information on how to reproduce this?
looking at your output it looks like your submodules may have already been broken since
your report is also incomplete -- you have not shared the command you ran and its output so I cannot help you further without that
There was definitively a problem with them, but the changes to these submodules date from months back, there's around 20 commits following those changes.
From the history, it was a simple
ahah -- is it possible you have this setting enabled? https://git-scm.com/docs/git-config#Documentation/git-config.txt-submodulerecurse
let me see if that's what can cause this ?