Skip to content

Commit 9ee580d

Browse files
authored
Merge pull request cli#3491 from junjieyuan/trunk
using filepath.Join() instead of path.Join() to fix wrong filepath on Windows
2 parents 5821065 + c57e30f commit 9ee580d

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

cmd/gh/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net"
88
"os"
99
"os/exec"
10-
"path"
1110
"path/filepath"
1211
"strings"
1312
"time"
@@ -259,7 +258,7 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) {
259258
}
260259

261260
repo := updaterEnabled
262-
stateFilePath := path.Join(config.ConfigDir(), "state.yml")
261+
stateFilePath := filepath.Join(config.ConfigDir(), "state.yml")
263262
return update.CheckForUpdate(client, stateFilePath, repo, currentVersion)
264263
}
265264

internal/config/config_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ func ConfigDir() string {
2828
}
2929

3030
func ConfigFile() string {
31-
return path.Join(ConfigDir(), "config.yml")
31+
return filepath.Join(ConfigDir(), "config.yml")
3232
}
3333

3434
func HostsConfigFile() string {
35-
return path.Join(ConfigDir(), "hosts.yml")
35+
return filepath.Join(ConfigDir(), "hosts.yml")
3636
}
3737

3838
func ParseDefaultConfig() (Config, error) {

internal/config/config_file_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func Test_parseConfig(t *testing.T) {
14-
defer StubConfig(`---
14+
defer stubConfig(`---
1515
hosts:
1616
github.com:
1717
user: monalisa
@@ -28,7 +28,7 @@ hosts:
2828
}
2929

3030
func Test_parseConfig_multipleHosts(t *testing.T) {
31-
defer StubConfig(`---
31+
defer stubConfig(`---
3232
hosts:
3333
example.com:
3434
user: wronguser
@@ -48,7 +48,7 @@ hosts:
4848
}
4949

5050
func Test_parseConfig_hostsFile(t *testing.T) {
51-
defer StubConfig("", `---
51+
defer stubConfig("", `---
5252
github.com:
5353
user: monalisa
5454
oauth_token: OTOKEN
@@ -64,7 +64,7 @@ github.com:
6464
}
6565

6666
func Test_parseConfig_hostFallback(t *testing.T) {
67-
defer StubConfig(`---
67+
defer stubConfig(`---
6868
git_protocol: ssh
6969
`, `---
7070
github.com:
@@ -89,7 +89,7 @@ example.com:
8989
}
9090

9191
func Test_parseConfig_migrateConfig(t *testing.T) {
92-
defer StubConfig(`---
92+
defer stubConfig(`---
9393
github.com:
9494
- user: keiyuri
9595
oauth_token: 123456
@@ -134,7 +134,7 @@ func Test_parseConfigFile(t *testing.T) {
134134

135135
for _, tt := range tests {
136136
t.Run(fmt.Sprintf("contents: %q", tt.contents), func(t *testing.T) {
137-
defer StubConfig(tt.contents, "")()
137+
defer stubConfig(tt.contents, "")()
138138
_, yamlRoot, err := parseConfigFile("config.yml")
139139
if tt.wantsErr != (err != nil) {
140140
t.Fatalf("got error: %v", err)

internal/config/testing.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"io"
66
"os"
7-
"path"
7+
"path/filepath"
88
)
99

1010
func StubBackupConfig() func() {
@@ -21,7 +21,7 @@ func StubBackupConfig() func() {
2121
func StubWriteConfig(wc io.Writer, wh io.Writer) func() {
2222
orig := WriteConfigFile
2323
WriteConfigFile = func(fn string, data []byte) error {
24-
switch path.Base(fn) {
24+
switch filepath.Base(fn) {
2525
case "config.yml":
2626
_, err := wc.Write(data)
2727
return err
@@ -37,10 +37,10 @@ func StubWriteConfig(wc io.Writer, wh io.Writer) func() {
3737
}
3838
}
3939

40-
func StubConfig(main, hosts string) func() {
40+
func stubConfig(main, hosts string) func() {
4141
orig := ReadConfigFile
4242
ReadConfigFile = func(fn string) ([]byte, error) {
43-
switch path.Base(fn) {
43+
switch filepath.Base(fn) {
4444
case "config.yml":
4545
if main == "" {
4646
return []byte(nil), os.ErrNotExist

0 commit comments

Comments
 (0)