Skip to content

Commit e2f0614

Browse files
authored
Merge pull request #385 from x-motemen/revert-378-rel_ssh
Revert "feat: enable relative path ssh URL"
2 parents f18c54e + cef2d00 commit e2f0614

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

url.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,12 @@ func newURL(ref string, ssh, forceMe bool) (*url.URL, error) {
112112
user := matched[1]
113113
host := matched[2]
114114
path := matched[3]
115-
// When two conditions below are satisfied:
116-
// 1. the path is a relative path, which not beginning with a slash, like `path/to/repo`.
117-
// 2. the host is not github.com, which doesn't support relative paths.
118-
// then we convert the given SCP style URL to a normal style and relative path URL using tilde, like `ssh://[email protected]/~/path/to/repo`.
119-
if strings.HasPrefix(path, "/") {
120-
path = strings.TrimPrefix(path, "/")
121-
} else if host != "github.com" {
122-
path = "~/" + path
123-
}
124-
ref = fmt.Sprintf("ssh://%s%s/%s", user, host, path)
115+
// If the path is a relative path not beginning with a slash like
116+
// `path/to/repo`, we might convert to like
117+
// `ssh://[email protected]/~/path/to/repo` using tilde, but
118+
// since GitHub doesn't support it, we treat relative and absolute
119+
// paths the same way.
120+
ref = fmt.Sprintf("ssh://%s%s/%s", user, host, strings.TrimPrefix(path, "/"))
125121
} else {
126122
// If ref is like "github.com/motemen/ghq" convert to "https://github.com/motemen/ghq"
127123
paths := strings.Split(ref, "/")

url_test.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,20 @@ func TestNewURL(t *testing.T) {
2020
expect: "https://github.com/motemen/pusheen-explorer",
2121
host: "github.com",
2222
}, {
23-
name: "scp to github", // Convert SCP-like URL to SSH URL
23+
name: "scp", // Convert SCP-like URL to SSH URL
2424
url: "[email protected]:motemen/pusheen-explorer.git",
2525
expect: "ssh://[email protected]/motemen/pusheen-explorer.git",
2626
host: "github.com",
2727
}, {
28-
name: "scp with root to github",
28+
name: "scp with root",
2929
url: "[email protected]:/motemen/pusheen-explorer.git",
3030
expect: "ssh://[email protected]/motemen/pusheen-explorer.git",
3131
host: "github.com",
3232
}, {
33-
name: "scp without user to github",
33+
name: "scp without user",
3434
url: "github.com:motemen/pusheen-explorer.git",
3535
expect: "ssh://github.com/motemen/pusheen-explorer.git",
3636
host: "github.com",
37-
}, {
38-
name: "scp to others",
39-
url: "[email protected]:repo/www.git",
40-
expect: "ssh://[email protected]/~/repo/www.git",
41-
host: "example.com",
42-
}, {
43-
name: "scp with root to others",
44-
url: "[email protected]:/repo/www.git",
45-
expect: "ssh://[email protected]/repo/www.git",
46-
host: "example.com",
47-
}, {
48-
name: "scp without user to others",
49-
url: "example.com:repo/www.git",
50-
expect: "ssh://example.com/~/repo/www.git",
51-
host: "example.com",
5237
}, {
5338
name: "different name repository",
5439
url: "motemen/ghq",

0 commit comments

Comments
 (0)