X Tutup
Skip to content

Commit 65e5ba9

Browse files
authored
Merge pull request cli#2493 from gunadhya/repo-clone-wiki
Initial fix for gh-repo-clone wiki
2 parents a77f3dd + 39a0a8c commit 65e5ba9

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

api/queries_repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Repository struct {
2727

2828
IsPrivate bool
2929
HasIssuesEnabled bool
30+
HasWikiEnabled bool
3031
ViewerPermission string
3132
DefaultBranchRef BranchRef
3233

@@ -94,6 +95,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
9495
owner { login }
9596
hasIssuesEnabled
9697
description
98+
hasWikiEnabled
9799
viewerPermission
98100
defaultBranchRef {
99101
name

pkg/cmd/repo/clone/clone.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func cloneRun(opts *CloneOptions) error {
8787

8888
var repo ghrepo.Interface
8989
var protocol string
90+
9091
if repositoryIsURL {
9192
repoURL, err := git.ParseURL(opts.Repository)
9293
if err != nil {
@@ -123,6 +124,12 @@ func cloneRun(opts *CloneOptions) error {
123124
}
124125
}
125126

127+
wantsWiki := strings.HasSuffix(repo.RepoName(), ".wiki")
128+
if wantsWiki {
129+
repoName := strings.TrimSuffix(repo.RepoName(), ".wiki")
130+
repo = ghrepo.NewWithHost(repo.RepoOwner(), repoName, repo.RepoHost())
131+
}
132+
126133
// Load the repo from the API to get the username/repo name in its
127134
// canonical capitalization
128135
canonicalRepo, err := api.GitHubRepo(apiClient, repo)
@@ -131,6 +138,14 @@ func cloneRun(opts *CloneOptions) error {
131138
}
132139
canonicalCloneURL := ghrepo.FormatRemoteURL(canonicalRepo, protocol)
133140

141+
// If repo HasWikiEnabled and wantsWiki is true then create a new clone URL
142+
if wantsWiki {
143+
if !canonicalRepo.HasWikiEnabled {
144+
return fmt.Errorf("The '%s' repository does not have a wiki", ghrepo.FullName(canonicalRepo))
145+
}
146+
canonicalCloneURL = strings.TrimSuffix(canonicalCloneURL, ".git") + ".wiki.git"
147+
}
148+
134149
cloneDir, err := git.RunClone(canonicalCloneURL, opts.GitArgs)
135150
if err != nil {
136151
return err

pkg/cmd/repo/clone/clone_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ func Test_RepoClone(t *testing.T) {
168168
args: "Owner/Repo",
169169
want: "git clone https://github.com/OWNER/REPO.git",
170170
},
171+
{
172+
name: "clone wiki",
173+
args: "Owner/Repo.wiki",
174+
want: "git clone https://github.com/OWNER/REPO.wiki.git",
175+
},
176+
{
177+
name: "wiki URL",
178+
args: "https://github.com/owner/repo.wiki",
179+
want: "git clone https://github.com/OWNER/REPO.wiki.git",
180+
},
171181
}
172182
for _, tt := range tests {
173183
t.Run(tt.name, func(t *testing.T) {
@@ -179,7 +189,8 @@ func Test_RepoClone(t *testing.T) {
179189
"name": "REPO",
180190
"owner": {
181191
"login": "OWNER"
182-
}
192+
},
193+
"hasWikiEnabled": true
183194
} } }
184195
`))
185196

0 commit comments

Comments
 (0)
X Tutup