diff --git a/api/queries_repo.go b/api/queries_repo.go index b60dfaa92..1ca7a92f8 100644 --- a/api/queries_repo.go +++ b/api/queries_repo.go @@ -27,6 +27,7 @@ type Repository struct { IsPrivate bool HasIssuesEnabled bool + HasWikiEnabled bool ViewerPermission string DefaultBranchRef BranchRef @@ -94,6 +95,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) { owner { login } hasIssuesEnabled description + hasWikiEnabled viewerPermission defaultBranchRef { name diff --git a/pkg/cmd/repo/clone/clone.go b/pkg/cmd/repo/clone/clone.go index 73f4d7187..ee2a2ecdf 100644 --- a/pkg/cmd/repo/clone/clone.go +++ b/pkg/cmd/repo/clone/clone.go @@ -87,6 +87,7 @@ func cloneRun(opts *CloneOptions) error { var repo ghrepo.Interface var protocol string + if repositoryIsURL { repoURL, err := git.ParseURL(opts.Repository) if err != nil { @@ -123,6 +124,12 @@ func cloneRun(opts *CloneOptions) error { } } + wantsWiki := strings.HasSuffix(repo.RepoName(), ".wiki") + if wantsWiki { + repoName := strings.TrimSuffix(repo.RepoName(), ".wiki") + repo = ghrepo.NewWithHost(repo.RepoOwner(), repoName, repo.RepoHost()) + } + // Load the repo from the API to get the username/repo name in its // canonical capitalization canonicalRepo, err := api.GitHubRepo(apiClient, repo) @@ -131,6 +138,14 @@ func cloneRun(opts *CloneOptions) error { } canonicalCloneURL := ghrepo.FormatRemoteURL(canonicalRepo, protocol) + // If repo HasWikiEnabled and wantsWiki is true then create a new clone URL + if wantsWiki { + if !canonicalRepo.HasWikiEnabled { + return fmt.Errorf("The '%s' repository does not have a wiki", ghrepo.FullName(canonicalRepo)) + } + canonicalCloneURL = strings.TrimSuffix(canonicalCloneURL, ".git") + ".wiki.git" + } + cloneDir, err := git.RunClone(canonicalCloneURL, opts.GitArgs) if err != nil { return err diff --git a/pkg/cmd/repo/clone/clone_test.go b/pkg/cmd/repo/clone/clone_test.go index e7aa57b08..f6b612202 100644 --- a/pkg/cmd/repo/clone/clone_test.go +++ b/pkg/cmd/repo/clone/clone_test.go @@ -168,6 +168,16 @@ func Test_RepoClone(t *testing.T) { args: "Owner/Repo", want: "git clone https://github.com/OWNER/REPO.git", }, + { + name: "clone wiki", + args: "Owner/Repo.wiki", + want: "git clone https://github.com/OWNER/REPO.wiki.git", + }, + { + name: "wiki URL", + args: "https://github.com/owner/repo.wiki", + want: "git clone https://github.com/OWNER/REPO.wiki.git", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -179,7 +189,8 @@ func Test_RepoClone(t *testing.T) { "name": "REPO", "owner": { "login": "OWNER" - } + }, + "hasWikiEnabled": true } } } `))