diff options
author | Jan Holesovsky <kendy@collabora.com> | 2018-11-14 15:20:14 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-11-22 11:25:10 +0100 |
commit | e1f067151fe853a9e8688a02d78670ad40d5f1d1 (patch) | |
tree | 9ad8880784ad5bb94dd8b8e17bddaaa93db37bc6 /.git-hooks | |
parent | 1874d71576d46e28b79fe2df87f379a28767dccc (diff) |
git hooks: Check that you are not committing to submodules by accident.
And also for a dangerous setting in the configuration that hides the
changes from you.
Change-Id: I99bad8024baf7048696d9602e857c253c20cb5c2
Reviewed-on: https://gerrit.libreoffice.org/63389
Tested-by: Jenkins
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
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: |