Skip to content

Commit d7969a5

Browse files
av-galgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c5877b commit d7969a5

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

git-svn.perl

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,12 +1279,20 @@ sub cmd_show_ignore {
12791279
$gs->prop_walk($gs->path, $r, sub {
12801280
my ($gs, $path, $props) = @_;
12811281
print STDOUT "\n# $path\n";
1282-
my $s = $props->{'svn:ignore'} or return;
1283-
$s =~ s/[\r\n]+/\n/g;
1284-
$s =~ s/^\n+//;
1285-
chomp $s;
1286-
$s =~ s#^#$path#gm;
1287-
print STDOUT "$s\n";
1282+
if (my $s = $props->{'svn:ignore'}) {
1283+
$s =~ s/[\r\n]+/\n/g;
1284+
$s =~ s/^\n+//;
1285+
chomp $s;
1286+
$s =~ s#^#$path#gm;
1287+
print STDOUT "$s\n";
1288+
}
1289+
if (my $s = $props->{'svn:global-ignores'}) {
1290+
$s =~ s/[\r\n]+/\n/g;
1291+
$s =~ s/^\n+//;
1292+
chomp $s;
1293+
$s =~ s#^#$path**/#gm;
1294+
print STDOUT "$s\n";
1295+
}
12881296
});
12891297
}
12901298

@@ -1315,16 +1323,25 @@ sub cmd_create_ignore {
13151323
# which git won't track
13161324
mkpath([$path]) unless -d $path;
13171325
my $ignore = $path . '.gitignore';
1318-
my $s = $props->{'svn:ignore'} or return;
13191326
open(GITIGNORE, '>', $ignore)
13201327
or fatal("Failed to open `$ignore' for writing: $!");
1321-
$s =~ s/[\r\n]+/\n/g;
1322-
$s =~ s/^\n+//;
1323-
chomp $s;
1324-
# Prefix all patterns so that the ignore doesn't apply
1325-
# to sub-directories.
1326-
$s =~ s#^#/#gm;
1327-
print GITIGNORE "$s\n";
1328+
if (my $s = $props->{'svn:ignore'}) {
1329+
$s =~ s/[\r\n]+/\n/g;
1330+
$s =~ s/^\n+//;
1331+
chomp $s;
1332+
# Prefix all patterns so that the ignore doesn't apply
1333+
# to sub-directories.
1334+
$s =~ s#^#/#gm;
1335+
print GITIGNORE "$s\n";
1336+
}
1337+
if (my $s = $props->{'svn:global-ignores'}) {
1338+
$s =~ s/[\r\n]+/\n/g;
1339+
$s =~ s/^\n+//;
1340+
chomp $s;
1341+
# Global ignores apply to sub-directories, so they are
1342+
# not prefixed.
1343+
print GITIGNORE "$s\n";
1344+
}
13281345
close(GITIGNORE)
13291346
or fatal("Failed to close `$ignore': $!");
13301347
command_noisy('add', '-f', $ignore);

0 commit comments

Comments
 (0)