[PATCH] contrib: Honor symbolic port in git-credential-netrc.

Maxim Cournoyer
2025-06-20T04:13:18Z

Symbolic ports were previously silently dropped, which made it
impossible to use them with git-credential-netrc. This is a supported
use case according to 'man git-send-email', for --smtp-server-port:

[...] symbolic port names (e.g. "submission" instead of 587) are
also accepted.
---
contrib/credential/netrc/git-credential-netrc.perl | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/contrib/credential/netrc/git-credential-netrc.perl b/contrib/credential/netrc/git-credential-netrc.perl
index 9fb998ae09..ad06000b9f 100755
--- a/contrib/credential/netrc/git-credential-netrc.perl
+++ b/contrib/credential/netrc/git-credential-netrc.perl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl

use strict;
use warnings;
@@ -267,7 +267,9 @@ sub load_netrc {
if (!defined $nentry->{machine}) {
next;
}
- if (defined $nentry->{port} && $nentry->{port} =~ m/^\d+$/) {
+ if (defined $nentry->{port} && $nentry->{port} =~ m/^[[:alnum:]]+$/) {
+ # Port may be either an integer or a symbolic
+ # name, e.g. "smtps".
$num_port = $nentry->{port};
delete $nentry->{port};
}

base-commit: 9520f7d9985d8879bddd157309928fc0679c8e92
--
2.49.0