Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- "**"
pull_request: {}
jobs:
test:
runs-on: ${{ matrix.os }}
Expand All @@ -19,6 +18,11 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 1.x
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
if: "matrix.os == 'windows-latest'"
- name: checkout
uses: actions/checkout@v3
- name: test
Expand Down
33 changes: 17 additions & 16 deletions cmd_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,21 @@ import (
"github.com/Songmu/gitconfig"
)

func samePath(lhs, rhs string) bool {
if runtime.GOOS != "windows" {
return lhs == rhs
}

lhs, _ = filepath.Abs(filepath.Clean(lhs))
rhs, _ = filepath.Abs(filepath.Clean(rhs))
return strings.ToLower(lhs) == strings.ToLower(rhs)
}

func samePaths(lhs, rhs string) bool {
if runtime.GOOS != "windows" {
return lhs == rhs
}
lhss := strings.Split(lhs, "\n")
rhss := strings.Split(rhs, "\n")
for i := range lhss {
if !samePath(lhss[i], rhss[i]) {
return false
}
}
return true
return samePathSlice(lhss, rhss)
}

func TestDoRoot(t *testing.T) {
testCases := []struct {
name string
setup func(t *testing.T)
expect, allExpect string
skipOnWin bool
}{{
name: "env",
setup: func(t *testing.T) {
Expand All @@ -60,6 +46,17 @@ func TestDoRoot(t *testing.T) {
},
expect: "/path/to/ghqroot11\n",
allExpect: "/path/to/ghqroot11\n/path/to/ghqroot12\n",
/*
If your gitconfig contains a path to the start of slash, and you get it with `git config --type=path`,
the behavior on Windows is strange. Specifically, on Windows with GitHub Actions, a Git
installation path such as "C:/Program Files/Git/mingw64" is appended immediately before the path.
This has been addressed in the following issue, which seems to have been resolved in the v2.34.0
release.
https://github.com/git-for-windows/git/pull/3472
However, Git on GitHub Actions is v2.39.2 at the time of this comment, and this problem continues
to occur. I'm not sure, so I'll skip the test for now.
*/
skipOnWin: true,
}, {
name: "default home",
setup: func(t *testing.T) {
Expand All @@ -74,13 +71,17 @@ func TestDoRoot(t *testing.T) {
setEnv(t, envGhqRoot, "")
setEnv(t, "GIT_CONFIG", fpath)
setEnv(t, "HOME", "/path/to/ghqhome")
setEnv(t, "USERPROFILE", "/path/to/ghqhome")
},
expect: "/path/to/ghqhome/ghq\n",
allExpect: "/path/to/ghqhome/ghq\n",
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.skipOnWin && runtime.GOOS == "windows" {
t.SkipNow()
}
defer func(orig []string) { _localRepositoryRoots = orig }(_localRepositoryRoots)
_localRepositoryRoots = nil
localRepoOnce = &sync.Once{}
Expand Down
22 changes: 18 additions & 4 deletions local_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ import (
"reflect"
"runtime"
"sort"
"strings"
"sync"
"testing"

"github.com/Songmu/gitconfig"
)

func samePathSlice(lhss, rhss []string) bool {
sort.Strings(lhss)
sort.Strings(rhss)
for i := range lhss {
if !samePath(lhss[i], rhss[i]) {
if len(lhss) != len(rhss) {
return false
}
lhssAbs := make([]string, len(lhss))
rhssAbs := make([]string, len(rhss))

for i, p := range lhss {
lhsAbs, _ := filepath.Abs(filepath.Clean(p))
lhssAbs[i] = strings.ToLower(lhsAbs)

rhsAbs, _ := filepath.Abs(filepath.Clean(rhss[i]))
rhssAbs[i] = strings.ToLower(rhsAbs)
}
sort.Strings(lhssAbs)
sort.Strings(rhssAbs)
for i := range lhssAbs {
if lhssAbs[i] != rhssAbs[i] {
return false
}
}
Expand Down