Merge pull request #2493 from gunadhya/repo-clone-wiki
Initial fix for gh-repo-clone wiki
This commit is contained in:
commit
65e5ba9da1
3 changed files with 29 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
} } }
|
||||
`))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue