about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--Documentation/public-inbox-fetch.pod9
-rw-r--r--lib/PublicInbox/Fetch.pm22
-rwxr-xr-xscript/public-inbox-fetch4
3 files changed, 25 insertions, 10 deletions
diff --git a/Documentation/public-inbox-fetch.pod b/Documentation/public-inbox-fetch.pod
index 833df862..1890ae75 100644
--- a/Documentation/public-inbox-fetch.pod
+++ b/Documentation/public-inbox-fetch.pod
@@ -43,6 +43,15 @@ If you wish to re-enable fetches to the epoch:
 
 Quiets down progress messages, also passed to L<git-fetch(1)>.
 
+=item -T REMOTE
+
+=item --try-remote REMOTE
+
+Try a given remote name instead of C<origin> or C<_grokmirror>.
+May be specified more than once.
+
+Default: C<origin>, C<_grokmirror>
+
 =item --exit-code
 
 Exit with C<127> if no updates are done.  This can be used in
diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm
index e5756fb6..0d4badbf 100644
--- a/lib/PublicInbox/Fetch.pm
+++ b/lib/PublicInbox/Fetch.pm
@@ -31,13 +31,17 @@ sub fetch_args ($$) {
 }
 
 sub remote_url ($$) {
-        my ($lei, $dir) = @_; # TODO: support non-"origin"?
-        my $cmd = [ qw(git config remote.origin.url) ];
-        my $fh = popen_rd($cmd, undef, { -C => $dir, 2 => $lei->{2} });
-        my $url = <$fh>;
-        close $fh or return;
-        $url =~ s!/*\n!!s;
-        $url;
+        my ($lei, $dir) = @_;
+        my $rn = $lei->{opt}->{'try-remote'} // [ 'origin', '_grokmirror' ];
+        for my $r (@$rn) {
+                my $cmd = [ qw(git config), "remote.$r.url" ];
+                my $fh = popen_rd($cmd, undef, { -C => $dir, 2 => $lei->{2} });
+                my $url = <$fh>;
+                close $fh or next;
+                $url =~ s!/*\n!!s;
+                return $url;
+        }
+        undef
 }
 
 sub do_manifest ($$$) {
@@ -110,7 +114,7 @@ sub do_fetch { # main entry point
         my ($ibx_uri, @git_dir, @epochs, $mg, @new_epoch, $skip);
         if ($ibx_ver == 1) {
                 my $url = remote_url($lei, $dir) //
-                        die "E: $dir missing remote.origin.url\n";
+                        die "E: $dir missing remote.*.url\n";
                 $ibx_uri = URI->new($url);
         } else { # v2:
                 require PublicInbox::MultiGit;
@@ -128,7 +132,7 @@ sub do_fetch { # main entry point
                                 $git_url = $url;
                                 $epoch = $nr;
                         } else {
-                                warn "W: $edir missing remote.origin.url\n";
+                                warn "W: $edir missing remote.*.url\n";
                                 my $pid = spawn([qw(git config -l)], undef,
                                         { 1 => $lei->{2}, 2 => $lei->{2} });
                                 waitpid($pid, 0);
diff --git a/script/public-inbox-fetch b/script/public-inbox-fetch
index d7d4ba47..f9bac4e3 100755
--- a/script/public-inbox-fetch
+++ b/script/public-inbox-fetch
@@ -16,12 +16,14 @@ options:
   --torsocks VAL      whether or not to wrap git and curl commands with
                       torsocks (default: `auto')
                       Must be one of: `auto', `no' or `yes'
+  -T NAME             Name of remote(s) to try (may be repeated)
+                      default: `origin' and `_grokmirror'
   --exit-code         exit with 127 if no updates
   --verbose | -v      increase verbosity (may be repeated)
     --quiet | -q      increase verbosity (may be repeated)
     -C DIR            chdir to specified directory
 EOF
-GetOptions($opt, qw(help|h quiet|q verbose|v+ C=s@ c=s@
+GetOptions($opt, qw(help|h quiet|q verbose|v+ C=s@ c=s@ try-remote|T=s@
         no-torsocks torsocks=s exit-code)) or die $help;
 if ($opt->{help}) { print $help; exit };
 require PublicInbox::Fetch; # loads Admin