[Libreoffice-commits] core.git: .git-hooks/pre-commit
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Nov 22 10:25:35 UTC 2018
.git-hooks/pre-commit | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
New commits:
commit e1f067151fe853a9e8688a02d78670ad40d5f1d1
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Nov 14 15:20:14 2018 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Nov 22 11:25:10 2018 +0100
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 at collabora.com>
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:
More information about the Libreoffice-commits
mailing list