Merge branch 'ag/git-svn-global-ignores'

"git svn" has been taught about svn:global-ignores property
recent versions of Subversion has.

* ag/git-svn-global-ignores:
  git-svn: mention `svn:global-ignores` in help+docs
  git-svn: use `svn:global-ignores` to create .gitignore
  git-svn: add public property `svn:global-ignores`
maint
Junio C Hamano 2024-08-21 12:02:23 -07:00
commit d97956b8bd
3 changed files with 42 additions and 25 deletions

View File

@ -431,14 +431,14 @@ Any other arguments are passed directly to 'git log'
independently of 'git svn' functions.

'create-ignore'::
Recursively finds the svn:ignore property on directories and
creates matching .gitignore files. The resulting files are staged to
be committed, but are not committed. Use -r/--revision to refer to a
specific revision.
Recursively finds the svn:ignore and svn:global-ignores properties
on directories and creates matching .gitignore files. The resulting
files are staged to be committed, but are not committed. Use
-r/--revision to refer to a specific revision.

'show-ignore'::
Recursively finds and lists the svn:ignore property on
directories. The output is suitable for appending to
Recursively finds and lists the svn:ignore and svn:global-ignores
properties on directories. The output is suitable for appending to
the $GIT_DIR/info/exclude file.

'mkdirs'::
@ -871,7 +871,7 @@ Tracking and contributing to the trunk of a Subversion-managed project
# Now commit your changes (that were committed previously using Git) to SVN,
# as well as automatically updating your working HEAD:
git svn dcommit
# Append svn:ignore settings to the default Git exclude file:
# Append svn:ignore and svn:global-ignores settings to the default Git exclude file:
git svn show-ignore >> .git/info/exclude
------------------------------------------------------------------------


View File

@ -219,11 +219,11 @@ my %cmd = (
"Set an SVN repository to a git tree-ish",
{ 'stdin' => \$_stdin, %cmt_opts, %fc_opts, } ],
'create-ignore' => [ \&cmd_create_ignore,
'Create a .gitignore per svn:ignore',
"Create a .gitignore per directory with SVN ignore properties",
{ 'revision|r=i' => \$_revision
} ],
'mkdirs' => [ \&cmd_mkdirs ,
"recreate empty directories after a checkout",
"Recreate empty directories after a checkout",
{ 'revision|r=i' => \$_revision } ],
'propget' => [ \&cmd_propget,
'Print the value of a property on a file or directory',
@ -234,7 +234,7 @@ my %cmd = (
'proplist' => [ \&cmd_proplist,
'List all properties of a file or directory',
{ 'revision|r=i' => \$_revision } ],
'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
'show-ignore' => [ \&cmd_show_ignore, "Show .gitignore patterns from SVN ignore properties",
{ 'revision|r=i' => \$_revision
} ],
'show-externals' => [ \&cmd_show_externals, "Show svn:externals listings",
@ -1279,12 +1279,20 @@ sub cmd_show_ignore {
$gs->prop_walk($gs->path, $r, sub {
my ($gs, $path, $props) = @_;
print STDOUT "\n# $path\n";
my $s = $props->{'svn:ignore'} or return;
$s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//;
chomp $s;
$s =~ s#^#$path#gm;
print STDOUT "$s\n";
if (my $s = $props->{'svn:ignore'}) {
$s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//;
chomp $s;
$s =~ s#^#$path#gm;
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,16 +1323,25 @@ sub cmd_create_ignore {
# which git won't track
mkpath([$path]) unless -d $path;
my $ignore = $path . '.gitignore';
my $s = $props->{'svn:ignore'} or return;
open(GITIGNORE, '>', $ignore)
or fatal("Failed to open `$ignore' for writing: $!");
$s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//;
chomp $s;
# Prefix all patterns so that the ignore doesn't apply
# to sub-directories.
$s =~ s#^#/#gm;
print GITIGNORE "$s\n";
if (my $s = $props->{'svn:ignore'}) {
$s =~ s/[\r\n]+/\n/g;
$s =~ s/^\n+//;
chomp $s;
# Prefix all patterns so that the ignore doesn't apply
# to sub-directories.
$s =~ s#^#/#gm;
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)
or fatal("Failed to close `$ignore': $!");
command_noisy('add', '-f', $ignore);

View File

@ -763,7 +763,7 @@ sub prop_walk {
# this needs to be updated.
++$interesting_props if /^svn:(?:ignore|keywords|executable
|eol-style|mime-type
|externals|needs-lock)$/x;
|externals|needs-lock|global-ignores)$/x;
}
&$sub($self, $p, $props) if $interesting_props;