git-svn: don't print v1-layout migration noise when there's nothing to migrate

`migrate_from_v1()' unconditionally announced and created `.git/svn'
when no legacy `refs/remotes/*' metadata existed to migrate. This
happens for example right after a `git init'.

Defer the logic until an actual candidate is found, matching
the existing pattern of `migrate_from_v0'

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
Wesley Schwengle 2026-08-27 19:43:44 -04:00 committed by Junio C Hamano
parent 94f057755b
commit 209363b3eb
2 changed files with 17 additions and 6 deletions

View File

@ -91,11 +91,6 @@ sub migrate_from_v1 {
# just in case somebody used 'svn' as their $id at some point...
return $migrated if -d $svn_dir && ! -f "$svn_dir/info/url";

print STDERR "Migrating from a git-svn v1 layout...\n";
mkpath([$svn_dir]);
print STDERR "Data from a previous version of git-svn exists, but\n\t",
"$svn_dir\n\t(required for this version ",
"($::VERSION) of git-svn) does not exist.\n";
my ($fh, $ctx) = command_output_pipe(qw/rev-parse --symbolic --all/);
while (<$fh>) {
my $x = $_;
@ -106,6 +101,15 @@ sub migrate_from_v1 {
next unless -f $info_url;
my $u = eval { ::file_to_s($info_url) };
next unless $u;
unless ($migrated) {
print STDERR "Migrating from a git-svn v1 layout...\n";
mkpath([$svn_dir]);
print STDERR "Data from a previous version of ",
"git-svn exists, but\n\t",
"$svn_dir\n\t(required for this version ",
"($::VERSION) of git-svn) does not ",
"exist.\n";
}
my $dn = dirname("$svn_dir/$x");
mkpath([$dn]) unless -d $dn;
if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
@ -127,7 +131,7 @@ sub migrate_from_v1 {
$migrated++;
}
command_close_pipe($fh, $ctx);
print STDERR "Done migrating from a git-svn v1 layout\n";
print STDERR "Done migrating from a git-svn v1 layout\n" if $migrated;
$migrated;
}


View File

@ -3,6 +3,13 @@
test_description='git svn metadata migrations from previous versions'
. ./lib-git-svn.sh

test_expect_success 'migrate is silent when there is nothing to migrate' '
git svn migrate 2>err.log &&
test_grep ! "Migrating from a git-svn v1 layout" err.log &&
test_grep ! "Data from a previous version of git-svn exists" err.log &&
! test -d "$GIT_DIR"/svn
'

test_expect_success 'setup old-looking metadata' '
cp "$GIT_DIR"/config "$GIT_DIR"/config-old-git-svn &&
mkdir import &&