Skip to content

Commit cb05ffb

Browse files
committed
Fix clone mixed bug
1 parent de70cd3 commit cb05ffb

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

cmd/serv.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"code.gitea.io/gitea/modules/process"
3030
repo_module "code.gitea.io/gitea/modules/repository"
3131
"code.gitea.io/gitea/modules/setting"
32+
"code.gitea.io/gitea/modules/util"
3233
"code.gitea.io/gitea/services/lfs"
3334

3435
"github.com/kballard/go-shellquote"
@@ -256,7 +257,7 @@ func runServ(ctx context.Context, c *cli.Command) error {
256257
// LowerCase and trim the repoPath as that's how they are stored.
257258
// This should be done after splitting the repoPath into username and reponame
258259
// so that username and reponame are not affected.
259-
repoPath = strings.ToLower(results.OwnerName + "/" + results.RepoName + ".git")
260+
repoPath = strings.ToLower(results.OwnerName + "/" + results.RepoName + util.Iif(results.IsWiki, ".wiki", "") + ".git")
260261

261262
// LFS SSH protocol
262263
if verb == git.CmdVerbLfsTransfer {

tests/integration/wiki_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
"strings"
1212
"testing"
1313

14+
auth_model "code.gitea.io/gitea/models/auth"
1415
"code.gitea.io/gitea/modules/git"
16+
api "code.gitea.io/gitea/modules/structs"
1517
"code.gitea.io/gitea/modules/util"
1618
"code.gitea.io/gitea/tests"
1719

@@ -71,3 +73,46 @@ func Test_RepoWikiPages(t *testing.T) {
7173
assert.Equal(t, expectedPagePaths[i], pagePath)
7274
})
7375
}
76+
77+
func Test_WikiClone(t *testing.T) {
78+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
79+
username := "user2"
80+
reponame := "repo1"
81+
wikiPath := username + "/" + reponame + ".wiki.git"
82+
keyname := "my-testing-key"
83+
baseAPITestContext := NewAPITestContext(t, username, "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
84+
85+
u.Path = wikiPath
86+
87+
t.Run("Clone HTTP", func(t *testing.T) {
88+
defer tests.PrintCurrentTest(t)()
89+
90+
dstLocalPath := t.TempDir()
91+
assert.NoError(t, git.Clone(t.Context(), u.String(), dstLocalPath, git.CloneRepoOptions{}))
92+
content, err := os.ReadFile(filepath.Join(dstLocalPath, "Home.md"))
93+
assert.NoError(t, err)
94+
assert.Equal(t, "# Home page\n\nThis is the home page!\n", string(content))
95+
})
96+
97+
t.Run("Clone SSH", func(t *testing.T) {
98+
defer tests.PrintCurrentTest(t)()
99+
100+
dstLocalPath := t.TempDir()
101+
sshURL := createSSHUrl(wikiPath, u)
102+
103+
withKeyFile(t, keyname, func(keyFile string) {
104+
var keyID int64
105+
t.Run("CreateUserKey", doAPICreateUserKey(baseAPITestContext, "test-key", keyFile, func(t *testing.T, key api.PublicKey) {
106+
keyID = key.ID
107+
}))
108+
assert.NotZero(t, keyID)
109+
110+
// Setup clone folder
111+
assert.NoError(t, git.Clone(t.Context(), sshURL.String(), dstLocalPath, git.CloneRepoOptions{}))
112+
content, err := os.ReadFile(filepath.Join(dstLocalPath, "Home.md"))
113+
assert.NoError(t, err)
114+
assert.Equal(t, "# Home page\n\nThis is the home page!\n", string(content))
115+
})
116+
})
117+
})
118+
}

0 commit comments

Comments
 (0)