]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mirror: fix --dry-run for forkgroups
authorEric Wong <e@80x24.org>
Mon, 28 Nov 2022 05:31:53 +0000 (05:31 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Nov 2022 23:38:57 +0000 (23:38 +0000)
We must not make permanent changes to the FS if --dry-run is in use.

lib/PublicInbox/LeiMirror.pm

index 3220f48de2f64f245ffb896b36a096fcebebfa15..00732128a809bdfa9404353ab449ab623869b7db 100644 (file)
@@ -378,7 +378,7 @@ sub forkgroup_prep {
        my $dir = "$os/$fg.git";
        my @cmd = ('git', "--git-dir=$dir", 'config');
        my $opt = +{ map { $_ => $self->{lei}->{$_} } (0..2) };
-       if (!-d $dir) {
+       if (!-d $dir && !$self->{dry_run}) {
                PublicInbox::Import::init_bare($dir);
                for ('repack.useDeltaIslands=true',
                                'pack.island=refs/remotes/([^/]+)/') {
@@ -391,15 +391,17 @@ sub forkgroup_prep {
        $rn =~ s/\.*?(?:\.git)?\.*?\z//s;
        $rn =~ s![\@\{\}/:\?\[\]\^~\s\f[:cntrl:]\*]!_!isg;
        $rn .= '-'.substr(sha256_hex($key), 0, 16);
-       # --no-tags is required to avoid conflicts
-       for ("url=$uri", "fetch=+refs/*:refs/remotes/$rn/*",
-                       'tagopt=--no-tags') {
-               my @kv = split(/=/, $_, 2);
-               $kv[0] = "remote.$rn.$kv[0]";
-               run_die([@cmd, @kv], undef, $opt);
+       unless ($self->{dry_run}) {
+               # --no-tags is required to avoid conflicts
+               for ("url=$uri", "fetch=+refs/*:refs/remotes/$rn/*",
+                               'tagopt=--no-tags') {
+                       my @kv = split(/=/, $_, 2);
+                       $kv[0] = "remote.$rn.$kv[0]";
+                       run_die([@cmd, @kv], undef, $opt);
+               }
        }
        $self->{-do_pack_refs} = 1; # likely coderepo
-       if (!-d $self->{cur_dst}) {
+       if (!-d $self->{cur_dst} && !$self->{dry_run}) {
                my $alt = File::Spec->rel2abs("$dir/objects");
                PublicInbox::Import::init_bare($self->{cur_dst});
                my $o = "$self->{cur_dst}/objects";