diff options
Diffstat (limited to '.git-hooks')
-rwxr-xr-x | .git-hooks/pre-commit | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit index 7ef34809165a..6c87dc890483 100755 --- a/.git-hooks/pre-commit +++ b/.git-hooks/pre-commit @@ -212,6 +212,57 @@ sub check_style($) } } +sub check_submodules($) +{ + my ($h) = @_; + + my $toplevel = `git rev-parse --show-toplevel`; + chomp $toplevel; + + # trick to get a list of submodules - directly read from the .gitmodules + open(SUBMODULES, "git config --file '$toplevel'/.gitmodules --get-regexp path | awk '{ print \$2 }' |" ) || die "Cannot run git config on the .gitmodules."; + while (<SUBMODULES>) + { + chomp; + + my $ignore = `git config submodule.$_.ignore`; + chomp $ignore; + if ($ignore eq 'all') + { + print <<EOM; +Error: Your git configuration has submodule.$_.ignore set to 'all'. + +This is dangerous and can lead to accidentally pushing unwanted changes to +submodules. + +To fix it, please do: + + git config --unset submodule.$_.ignore + +EOM + exit(1); + } + + my $diff = `git diff --cached --name-only -z $h -- $_`; + chomp $diff; + if ($diff ne '') + { + print <<EOM; +Error: You are trying to commit changes to submodule $_ from the main repo. + +Please do not do that, commit only to the submodule, the git hook on the +server will make sure the appropriate change is mirrored in the main repo. + +To remove the change, you can do: + + git submodule update $_ + +EOM + exit(1); + } + } +} + # Do the work :-) # Initial commit: diff against an empty tree object @@ -282,6 +333,9 @@ check_style($against); # catch missing author info check_author(); +# catch commits to the submodules +check_submodules($against); + # all OK exit( 0 ); # vi:set shiftwidth=4 expandtab: |