Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
262b5931
Kaydet (Commit)
262b5931
authored
Agu 16, 2011
tarafından
Norbert Thiebaud
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
put git hook on a diet. concentrate on safe, cheap and globally useful
üst
04d2e646
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
93 deletions
+32
-93
pre-commit
git-hooks/pre-commit
+32
-93
No files found.
git-hooks/pre-commit
Dosyayı görüntüle @
262b5931
...
...
@@ -6,23 +6,24 @@
# if it wants to stop the commit.
use
strict
;
use
File::
Temp
qw/ :mktemp /
;
use
File::
Copy
;
use
Cwd
;
#use File::Copy;
#use Cwd;
$ENV
{
LC_ALL
}
=
"C"
;
sub
check_whitespaces
($
$
)
sub
check_whitespaces
($)
{
my
(
$h
,
$src_exts
)
=
@_
;
my
(
$h
)
=
@_
;
my
$src_limited
=
"c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml"
;
my
$src_full
=
"c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml"
;
my
$found_bad
=
0
;
my
$filename
;
my
$reported_filename
=
""
;
my
$lineno
;
sub
bad_line
{
my
(
$why
,
$line
)
=
@_
;
if
(
$filename
=~
/\.($src_exts
)$/
)
{
my
(
$why
,
$line
,
$file_filter
)
=
@_
;
if
(
!
defined
$file_filter
||
$filename
=~
/\.($file_filter
)$/
)
{
if
(
!
$found_bad
)
{
print
STDERR
"*\n"
;
print
STDERR
"* You have some suspicious patch lines:\n"
;
...
...
@@ -55,13 +56,13 @@ sub check_whitespaces($$)
$lineno
++
;
chomp
;
if
(
/\s$/
)
{
bad_line
(
"trailing whitespace"
,
$_
);
bad_line
(
"trailing whitespace"
,
$_
,
$src_limited
);
}
if
(
/^\s* /
)
{
bad_line
(
"indent SP followed by a TAB"
,
$_
);
bad_line
(
"indent SP followed by a TAB"
,
$_
,
$src_limited
);
}
if
(
/^(?:[<>=]){7}/
)
{
bad_line
(
"unresolved merge conflict"
,
$
_
);
if
(
/^(?:[<>=]){7}
$
/
)
{
bad_line
(
"unresolved merge conflict"
,
$
src_full
);
}
}
}
...
...
@@ -93,35 +94,35 @@ if ( $allownonascii ne "true" &&
LC_ALL=C tr -d '[ -~]\\0'`
ne
""
)
{
print
<<EOM;
Error: Attempt to add a non-ascii file name.
"
Error: Attempt to add a non-ascii file name.
This can cause problems if you want to work
"
with people on other platforms.
"
This can cause problems if you want to work
with people on other platforms.
To be portable it is advisable to rename the file ...
"
To be portable it is advisable to rename the file ...
If you know what you are doing you can disable this
"
check using:
"
If you know what you are doing you can disable this
check using:
git config hooks.allownonascii true
"
git config hooks.allownonascii true
EOM
exit
(
1
);
}
# check for missing doxygen comments in new files
my
$doxycheck
=
"../../bin/find-undocumented-classes"
;
if
(
!
-
e
$doxycheck
)
{
# bootstrap repo
$doxycheck
=~
s
|..
/../
||
;
}
open
(
FILES
,
"git diff-index --cached --name-only --diff-filter=A $against |"
)
||
die
"Cannot run git diff-index."
;
while
(
my
$file
=
<
FILES
>
)
{
chomp
(
$file
);
if
(
$file
=~
/\.hxx$/
)
{
system
(
"$doxycheck -q $file | sed 's|"
.
getcwd
()
.
"/||;'"
);
}
}
#
my $doxycheck = "../../bin/find-undocumented-classes";
#
if (! -e $doxycheck) {
#
# bootstrap repo
#
$doxycheck =~ s|../../||;
#
}
#
open(FILES, "git diff-index --cached --name-only --diff-filter=A $against |") || die "Cannot run git diff-index.";
#
while (my $file = <FILES>) {
#
chomp($file);
#
if ($file =~ /\.hxx$/) {
#
system("$doxycheck -q $file | sed 's|".getcwd()."/||;'");
#
}
#
}
# run 'msgcat --nowrap' when committing *.po files
open
(
FILES
,
"git diff-index --cached --name-only $against |"
)
||
die
"Cannot run git diff-index."
;
...
...
@@ -133,70 +134,8 @@ while (my $file = <FILES>) {
}
}
# be strict about tabs - we don't want them at all, setup your editor
# correctly ;-)
my
$err_ext
=
""
;
my
$src_exts
=
"c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml"
;
open
(
FILES
,
"git diff-index --cached --name-only $against |"
)
||
die
"Cannot run git diff-index."
;
while
(
my
$file
=
<
FILES
>
)
{
chomp
(
$file
);
if
(
$file
ne
"GNUmakefile"
&&
$file
=~
/\.($src_exts)$/
)
{
open
(
F
,
"git diff-index -p --cached $against -- '$file' |"
);
while
(
my
$line
=
<
F
>
)
{
if
(
$line
=~
/^\+ *\t/
)
{
$err_ext
.=
"$file\n"
;
last
;
}
}
}
close
(
F
);
}
close
(
FILES
);
if
(
$err_ext
ne
""
)
{
print
<<EOM;
Error: Your change in the following files introduces tabs in indentation:
$err_ext
Please setup your editor not to use tabs, fix the files, and try again.
We have had enough trouble with tabs in the past :-(
EOM
exit
(
1
);
}
# check for old licenses
my
$check_licenses
=
'^+.*\(Sun Industry Standards Source License Version\|GNU Lesser General Public License Version 2.1\)'
;
my
$err_licenses
=
`git diff-index --cached --name-only $against | while read FILE ; do \
if git diff-index -p --cached $against -- "\$FILE" | grep -qs "$check_licenses" ; then \
echo "\$FILE" \
fi \
done`
;
chomp
(
$err_licenses
);
if
(
$err_licenses
ne
""
&&
$err_licenses
ne
"git-hooks/pre-commit"
)
{
print
<<EOM;
Error: Your change in the following files introduces old licenses:
$err_licenses
Please check with the author(s) that they agree with upgrading the
license to LGPL3, and change the license accondingly.
EOM
exit
(
1
);
}
# fix whitespace in code
check_whitespaces
(
$against
,
$src_exts
);
# check the rest of the files
my
$filter_patches
=
`git diff-index --check --cached $against -- | sed '/\.\(diff\|patch\):/,/.*/d'`
;
chomp
(
$filter_patches
);
if
(
$filter_patches
ne
""
)
{
print
"WARNING:\n\n$filter_patches\n"
;
}
check_whitespaces
(
$against
);
# all OK
exit
(
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment