git-svn: use svn:global-ignores to create .gitignore

`svn:global-ignores` contains a list of file patterns that should
not be tracked in version control. The syntax of these patterns is
the same as `svn:ignore`. Their semantics differ: patterns in
`svn:global-ignores` apply to all paths under the directory where
they apply, while `svn:ignore` only applies to the directory's
immediate children.

Signed-off-by: Alex Galvin <agalvin@comqi.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Alex Galvin
2024-07-18 20:47:37 +00:00
committed by Junio C Hamano
parent 5c5877b93c
commit d7969a5127

View File

@ -1279,12 +1279,20 @@ sub cmd_show_ignore {
$gs->prop_walk($gs->path, $r, sub { $gs->prop_walk($gs->path, $r, sub {
my ($gs, $path, $props) = @_; my ($gs, $path, $props) = @_;
print STDOUT "\n# $path\n"; print STDOUT "\n# $path\n";
my $s = $props->{'svn:ignore'} or return; if (my $s = $props->{'svn:ignore'}) {
$s =~ s/[\r\n]+/\n/g; $s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//; $s =~ s/^\n+//;
chomp $s; chomp $s;
$s =~ s#^#$path#gm; $s =~ s#^#$path#gm;
print STDOUT "$s\n"; print STDOUT "$s\n";
}
if (my $s = $props->{'svn:global-ignores'}) {
$s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//;
chomp $s;
$s =~ s#^#$path**/#gm;
print STDOUT "$s\n";
}
}); });
} }
@ -1315,9 +1323,9 @@ sub cmd_create_ignore {
# which git won't track # which git won't track
mkpath([$path]) unless -d $path; mkpath([$path]) unless -d $path;
my $ignore = $path . '.gitignore'; my $ignore = $path . '.gitignore';
my $s = $props->{'svn:ignore'} or return;
open(GITIGNORE, '>', $ignore) open(GITIGNORE, '>', $ignore)
or fatal("Failed to open `$ignore' for writing: $!"); or fatal("Failed to open `$ignore' for writing: $!");
if (my $s = $props->{'svn:ignore'}) {
$s =~ s/[\r\n]+/\n/g; $s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//; $s =~ s/^\n+//;
chomp $s; chomp $s;
@ -1325,6 +1333,15 @@ sub cmd_create_ignore {
# to sub-directories. # to sub-directories.
$s =~ s#^#/#gm; $s =~ s#^#/#gm;
print GITIGNORE "$s\n"; print GITIGNORE "$s\n";
}
if (my $s = $props->{'svn:global-ignores'}) {
$s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//;
chomp $s;
# Global ignores apply to sub-directories, so they are
# not prefixed.
print GITIGNORE "$s\n";
}
close(GITIGNORE) close(GITIGNORE)
or fatal("Failed to close `$ignore': $!"); or fatal("Failed to close `$ignore': $!");
command_noisy('add', '-f', $ignore); command_noisy('add', '-f', $ignore);