Kaydet (Commit) e1f06715 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

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: 's avatarJan Holesovsky <kendy@collabora.com>
üst 1874d715
...@@ -212,6 +212,57 @@ sub check_style($) ...@@ -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 :-) # Do the work :-)
# Initial commit: diff against an empty tree object # Initial commit: diff against an empty tree object
...@@ -282,6 +333,9 @@ check_style($against); ...@@ -282,6 +333,9 @@ check_style($against);
# catch missing author info # catch missing author info
check_author(); check_author();
# catch commits to the submodules
check_submodules($against);
# all OK # all OK
exit( 0 ); exit( 0 );
# vi:set shiftwidth=4 expandtab: # vi:set shiftwidth=4 expandtab:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment