From 6968c91707d51f6a60d476cc2f5d65a660146813 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 27 Jun 2020 10:03:58 +0000 Subject: watch: support ~/.netrc via Net::Netrc While git-credential-netrc exists in git.git contrib/, it may not be widely known or installed. Net::Netrc is already a standard part of most (if not all) Perl installations, so use it directly if available. --- lib/PublicInbox/GitCredential.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/PublicInbox/GitCredential.pm') diff --git a/lib/PublicInbox/GitCredential.pm b/lib/PublicInbox/GitCredential.pm index 826e7a55..c6da6a09 100644 --- a/lib/PublicInbox/GitCredential.pm +++ b/lib/PublicInbox/GitCredential.pm @@ -25,6 +25,21 @@ sub run ($$) { close $out_r or die "`git credential $op' failed: \$!=$! \$?=$?\n"; } +sub check_netrc ($) { + my ($self) = @_; + + # part of the standard library, but distributions may split it out + eval { require Net::Netrc }; + if ($@) { + warn "W: Net::Netrc missing: $@\n"; + return; + } + if (my $x = Net::Netrc->lookup($self->{host}, $self->{username})) { + $self->{username} //= $x->login; + $self->{password} = $x->password; + } +} + sub fill { my ($self) = @_; my $out_r = run($self, 'fill'); -- cgit v1.2.3-24-ge0c7