On 07/29/2011 11:01 AM, Miklos Vajna wrote:
On Wed, Jul 27, 2011 at 03:53:18PM +0200, Thomas Arnhold<thomas@arnhold.org> wrote:
I think this was not intended. Simple solution would be to add some
'<<<<<<< HEAD' .* '=======' .* '>>>>>>> master' stuff to git hooks. So
git would block commits with conflicts.
Good idea - care to send a patch? The pre-commit hook is at
git-hooks/pre-commit in bootstrap.git.
Yeah, I've already found that file. Strangely we already have such a
check:
http://cgit.freedesktop.org/libreoffice/bootstrap/tree/git-hooks/pre-commit#n61
And this check works! I've added a suspicious line to a random file
'<<<<<<< HEAD' and git commit won't accept this with the according error
message.
So if you do a simple 'git commit' you won't be able to commit those
lines. But if you are in a merge conflict and have to run 'git add FILE'
and 'git rebase --continue' those lines are accepted. That's why Bjoerns
merge had those in there...
So I tried to add an additional hook 'pre-rebase' (see attachment), but
it doesn't work. This is a modification of 'pre-commit'. Maybe the
problem occurs on 'git add FILE' and not at the step 'git rebase
--continue'. But for 'git add' there are no hooks as far as I know.
You could try to reproduce it:
git reset --hard HEAD~1
generate a merge conflict
git commit
git pull -r
git add ...
git rebase --continue
...
Thomas
#!/usr/bin/env perl
# A hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message
# if it wants to stop the commit.
use strict;
use File::Temp qw/ :mktemp /;
use File::Copy;
use Cwd;
$ENV{LC_ALL} = "C";
sub check_whitespaces($)
{
my ($h) = @_;
my $found_bad = 0;
my $filename;
my $reported_filename = "";
my $lineno;
sub bad_line {
my ($why, $line) = @_;
if (!$found_bad) {
print STDERR "*\n";
print STDERR "* You have some suspicious patch lines:\n";
print STDERR "*\n";
$found_bad = 1;
}
if ($reported_filename ne $filename) {
print STDERR "* In $filename\n";
$reported_filename = $filename;
}
print STDERR "* $why (line $lineno)\n";
print STDERR "$filename:$lineno:$line\n";
}
open( FILES, "git-diff-index -p -M --cached $h |" ) || die "Cannot run git diff-index.";
while (<FILES>) {
if (m|^diff --git a/(.*) b/\1$|) {
$filename = $1;
next;
}
if (/^@@ -\S+ \+(\d+)/) {
$lineno = $1 - 1;
next;
}
if (/^ /) {
$lineno++;
next;
}
if (s/^\+//) {
$lineno++;
chomp;
if (/^(?:[<>=]){7}/) {
bad_line("unresolved merge conflict", $_);
}
}
}
if ( $found_bad)
{
exit($found_bad);
}
}
# Do the work :-)
# Initial commit: diff against an empty tree object
my $against="4b825dc642cb6eb9a060e54bf8d69288fbee4904";
if ( system( "git rev-parse --verify HEAD >/dev/null 2>&1" ) == 0 ) {
$against="HEAD"
}
# fix whitespace in code
check_whitespaces( $against );
# all OK
exit( 0 );
# vi:set shiftwidth=4 expandtab:
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.