Skip to content

Commit 6ea1e82

Browse files
authored
Merge branch 'main' into drop-unused-clone-function
2 parents 4bec958 + 684449b commit 6ea1e82

File tree

7 files changed

+54
-98
lines changed

7 files changed

+54
-98
lines changed

config/netrc.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

config/netrc_nix.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/netrc_windows.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

creds/creds_nix.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

creds/creds_windows.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

creds/netrc.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net"
55
"os"
66
"path/filepath"
7+
"runtime"
78
"strings"
89
"sync"
910

@@ -16,6 +17,9 @@ type NetrcFinder interface {
1617
FindMachine(string, string) *netrc.Machine
1718
}
1819

20+
const netrcBasename = ".netrc"
21+
const netrcAltBasename = "_netrc"
22+
1923
func ParseNetrc(osEnv config.Environment) (NetrcFinder, string, error) {
2024
home, _ := osEnv.Get("HOME")
2125
if len(home) == 0 {
@@ -24,7 +28,16 @@ func ParseNetrc(osEnv config.Environment) (NetrcFinder, string, error) {
2428

2529
nrcfilename := filepath.Join(home, netrcBasename)
2630
if _, err := os.Stat(nrcfilename); err != nil {
27-
return &noFinder{}, nrcfilename, nil
31+
// If on Windows, try _netrc instead
32+
if runtime.GOOS == "windows" {
33+
altFilename := filepath.Join(home, netrcAltBasename)
34+
if _, errAlt := os.Stat(altFilename); errAlt != nil {
35+
return &noFinder{}, altFilename, nil
36+
}
37+
nrcfilename = altFilename
38+
} else {
39+
return &noFinder{}, nrcfilename, nil
40+
}
2841
}
2942

3043
f, err := netrc.ParseFile(nrcfilename)

t/t-credentials.sh

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -437,61 +437,60 @@ state[]=lfstest:state2"
437437
)
438438
end_test
439439

440-
441-
if [[ $(uname) == *"MINGW"* ]]; then
442-
NETRCFILE="$HOME/_netrc"
443-
else
444-
NETRCFILE="$HOME/.netrc"
440+
NETRCFILES=".netrc"
441+
if [ "$IS_WINDOWS" -eq 1 ]; then
442+
NETRCFILES+=" _netrc"
445443
fi
446444

445+
for netrcfile in $NETRCFILES; do
446+
begin_test "credentials from netrc ($netrcfile)"
447+
(
448+
set -e
447449

448-
begin_test "credentials from netrc"
449-
(
450-
set -e
450+
printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >"$HOME/$netrcfile"
451+
echo $HOME
452+
echo "GITSERVER $GITSERVER"
453+
cat "$HOME/$netrcfile"
451454

452-
printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >> "$NETRCFILE"
453-
echo $HOME
454-
echo "GITSERVER $GITSERVER"
455-
cat $NETRCFILE
455+
# prevent prompts on Windows particularly
456+
export SSH_ASKPASS=
456457

457-
# prevent prompts on Windows particularly
458-
export SSH_ASKPASS=
458+
reponame="netrctest-$netrcfile"
459+
setup_remote_repo "$reponame"
459460

460-
reponame="netrctest"
461-
setup_remote_repo "$reponame"
461+
clone_repo "$reponame" "${reponame}-assert"
462462

463-
clone_repo "$reponame" repo
463+
# Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
464+
git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
465+
git lfs env
464466

465-
# Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
466-
git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
467-
git lfs env
467+
git lfs track "*.dat"
468+
echo "push a" > a.dat
469+
git add .gitattributes a.dat
470+
git commit -m "add a.dat"
468471

469-
git lfs track "*.dat"
470-
echo "push a" > a.dat
471-
git add .gitattributes a.dat
472-
git commit -m "add a.dat"
472+
GIT_TRACE=1 git lfs push netrc main 2>&1 | tee push.log
473+
grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
474+
echo "any netrc credential calls:"
475+
[ "4" -eq "$(cat push.log | grep "netrc: git credential" | wc -l)" ]
473476

474-
GIT_TRACE=1 git lfs push netrc main 2>&1 | tee push.log
475-
grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
476-
echo "any netrc credential calls:"
477-
[ "4" -eq "$(cat push.log | grep "netrc: git credential" | wc -l)" ]
477+
echo "any netrc credential fills:"
478+
[ "2" -eq "$(cat push.log | grep "netrc: git credential fill" | wc -l)" ]
478479

479-
echo "any netrc credential fills:"
480-
[ "2" -eq "$(cat push.log | grep "netrc: git credential fill" | wc -l)" ]
481-
482-
echo "any netrc credential approvals:"
483-
[ "2" -eq "$(cat push.log | grep "netrc: git credential approve" | wc -l)" ]
484-
)
485-
end_test
480+
echo "any netrc credential approvals:"
481+
[ "2" -eq "$(cat push.log | grep "netrc: git credential approve" | wc -l)" ]
482+
)
483+
end_test
484+
done
486485

487486
begin_test "credentials from netrc with unknown keyword"
488487
(
489488
set -e
490489

491-
printf "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >> "$NETRCFILE"
490+
printf "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >"$HOME/.netrc"
492491
echo $HOME
493492
echo "GITSERVER $GITSERVER"
494-
cat $NETRCFILE
493+
cat "$HOME/.netrc"
495494

496495
# prevent prompts on Windows particularly
497496
export SSH_ASKPASS=
@@ -527,10 +526,10 @@ begin_test "credentials from netrc with bad password"
527526
(
528527
set -e
529528

530-
printf "machine localhost\nlogin netrcuser\npassword badpass\n" >> "$NETRCFILE"
529+
printf "machine localhost\nlogin netrcuser\npassword badpass\n" >"$HOME/.netrc"
531530
echo $HOME
532531
echo "GITSERVER $GITSERVER"
533-
cat $NETRCFILE
532+
cat "$HOME/.netrc"
534533

535534
# prevent prompts on Windows particularly
536535
export SSH_ASKPASS=
@@ -558,10 +557,10 @@ begin_test "credentials with bad netrc creds will retry"
558557
(
559558
set -e
560559

561-
printf "machine localhost\nlogin netrcuser\npassword badpassretry\n" >> "$NETRCFILE"
560+
printf "machine localhost\nlogin netrcuser\npassword badpassretry\n" >"$HOME/.netrc"
562561
echo $HOME
563562
echo "GITSERVER $GITSERVER"
564-
cat $NETRCFILE
563+
cat "$HOME/.netrc"
565564

566565
# prevent prompts on Windows particularly
567566
export SSH_ASKPASS=

0 commit comments

Comments
 (0)