contrib: warn for invalid netrc file ports in git-credential-netrc

Invalid ports were previously silently dropped; now a warning message is produced. Signed-off-by: Maxim Cournoyer <maxim@guixotic.coop> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Maxim Cournoyer committed Jun 25, 2025 at 23:25 UTC 53ca38298d69529e59e33a21e63040aef509bbf8
1 file changed +8 -3
contrib/credential/netrc/git-credential-netrc.perl
+8 -3
@@ -267,9 +267,14 @@ sub load_netrc {
267 if (!defined $nentry->{machine}) {
268 next;
269 }
270 - if (defined $nentry->{port} && $nentry->{port} =~ m/^\d+$/) {
271 - $num_port = $nentry->{port};
272 - delete $nentry->{port};
270 + if (defined $nentry->{port}) {
271 + if ($nentry->{port} =~ m/^\d+$/) {
272 + $num_port = $nentry->{port};
273 + delete $nentry->{port};
274 + } else {
275 + printf(STDERR "ignoring invalid port `%s' " .
276 + "from netrc file\n", $nentry->{port});
277 + }
278 }
279
280 # create the new entry for the credential helper protocol