]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei config: send `git config' errors to pager
authorEric Wong <e@80x24.org>
Sun, 24 Sep 2023 05:42:12 +0000 (05:42 +0000)
committerEric Wong <e@80x24.org>
Sun, 24 Sep 2023 18:56:07 +0000 (18:56 +0000)
Our previous use of lei->cfg_dump was wrong as the extra arg was
never supported.  Instead, we need to capture the output of
`git config' and send it to the pager if ->cfg_dump fails.  We'll
also add a note to the user to quit the pager to continue.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiConfig.pm

index a6d92eec5a16f12110c2249f561bc8ff8be5e668..488006e0e141dcf6ba89ab462a1b616ea4e10661 100644 (file)
@@ -1098,7 +1098,7 @@ sub pgr_err {
        my ($self, @msg) = @_;
        return warn(@msg) unless $self->{sock} && -t $self->{2};
        start_pager($self, { LESS => 'RX' }); # no 'F' so we prompt
-       print { $self->{2} } @msg;
+       say { $self->{2} } @msg, '# -quit pager to continue-';
        $self->{2}->autoflush(1);
        stop_pager($self);
        send($self->{sock}, 'wait', 0); # wait for user to quit pager
index 23be9aaf5bb212667d2c0813b0d94c9fad919350..fd4b0eca494d446c96789af65f989017eacf5517 100644 (file)
@@ -4,6 +4,8 @@ package PublicInbox::LeiConfig;
 use strict;
 use v5.10.1;
 use PublicInbox::PktOp;
+use Fcntl qw(SEEK_SET);
+use autodie qw(open seek);
 
 sub cfg_do_edit ($;$) {
        my ($self, $reason) = @_;
@@ -22,8 +24,14 @@ sub cfg_do_edit ($;$) {
 sub cfg_edit_done { # PktOp
        my ($self) = @_;
        eval {
-               my $cfg = $self->{lei}->cfg_dump($self->{-f}, $self->{lei}->{2})
-                       // return cfg_do_edit($self, "\n");
+               open my $fh, '+>', undef or die "open($!)";
+               my $cfg = do {
+                       local $self->{lei}->{2} = $fh;
+                       $self->{lei}->cfg_dump($self->{-f});
+               } or do {
+                       seek($fh, 0, SEEK_SET);
+                       return cfg_do_edit($self, do { local $/; <$fh> });
+               };
                $self->cfg_verify($cfg) if $self->can('cfg_verify');
        };
        $self->{lei}->fail($@) if $@;