Skip to content

Commit d378539

Browse files
committed
Fix the tests
Signed-off-by: Andrew Thornton <[email protected]>
1 parent d78a75d commit d378539

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func (repo *Repository) DeleteUncyclo() error {
499499
}
500500

501501
func (repo *Repository) deleteUncyclo(e Engine) error {
502-
wikiPaths := []string{repo.UncycloPath(), repo.LocalUncycloPath()}
502+
wikiPaths := []string{repo.UncycloPath()}
503503
for _, wikiPath := range wikiPaths {
504504
removeAllWithNotice(e, "Delete repository wiki", wikiPath)
505505
}

models/user.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -922,17 +922,6 @@ func ChangeUserName(u *User, newUserName string) (err error) {
922922
return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
923923
}
924924

925-
// Delete all local copies of repository wiki that user owns.
926-
if err = x.BufferSize(setting.IterateBufferSize).
927-
Where("owner_id=?", u.ID).
928-
Iterate(new(Repository), func(idx int, bean interface{}) error {
929-
repo := bean.(*Repository)
930-
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalUncycloPath())
931-
return nil
932-
}); err != nil {
933-
return fmt.Errorf("Delete repository wiki local copy: %v", err)
934-
}
935-
936925
// Do not fail if directory does not exist
937926
if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
938927
return fmt.Errorf("Rename user directory: %v", err)

models/wiki_test.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
package models
66

77
import (
8-
"path"
98
"path/filepath"
109
"testing"
1110

11+
"code.gitea.io/gitea/modules/git"
1212
"code.gitea.io/gitea/modules/setting"
1313

14-
"github.com/Unknwon/com"
1514
"github.com/stretchr/testify/assert"
1615
)
1716

@@ -145,13 +144,6 @@ func TestRepository_InitUncyclo(t *testing.T) {
145144
assert.True(t, repo2.HasUncyclo())
146145
}
147146

148-
func TestRepository_LocalUncycloPath(t *testing.T) {
149-
PrepareTestEnv(t)
150-
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
151-
expected := filepath.Join(setting.AppDataPath, setting.Repository.Local.LocalUncycloPath, "1")
152-
assert.Equal(t, expected, repo.LocalUncycloPath())
153-
}
154-
155147
func TestRepository_AddUncycloPage(t *testing.T) {
156148
assert.NoError(t, PrepareTestDatabase())
157149
const wikiContent = "This is the wiki content"
@@ -166,8 +158,15 @@ func TestRepository_AddUncycloPage(t *testing.T) {
166158
t.Run("test wiki exist: "+wikiName, func(t *testing.T) {
167159
t.Parallel()
168160
assert.NoError(t, repo.AddUncycloPage(doer, wikiName, wikiContent, commitMsg))
169-
expectedPath := path.Join(repo.LocalUncycloPath(), UncycloNameToFilename(wikiName))
170-
assert.True(t, com.IsExist(expectedPath))
161+
// Now need to show that the page has been added:
162+
gitRepo, err := git.OpenRepository(repo.UncycloPath())
163+
assert.NoError(t, err)
164+
masterTree, err := gitRepo.GetTree("master")
165+
assert.NoError(t, err)
166+
wikiPath := UncycloNameToFilename(wikiName)
167+
entry, err := masterTree.GetTreeEntryByPath(wikiPath)
168+
assert.NoError(t, err)
169+
assert.Equal(t, wikiPath, entry.Name(), "%s not addded correctly", wikiName)
171170
})
172171
}
173172

@@ -200,11 +199,20 @@ func TestRepository_EditUncycloPage(t *testing.T) {
200199
} {
201200
PrepareTestEnv(t)
202201
assert.NoError(t, repo.EditUncycloPage(doer, "Home", newUncycloName, newUncycloContent, commitMsg))
203-
newPath := path.Join(repo.LocalUncycloPath(), UncycloNameToFilename(newUncycloName))
204-
assert.True(t, com.IsExist(newPath))
202+
203+
// Now need to show that the page has been added:
204+
gitRepo, err := git.OpenRepository(repo.UncycloPath())
205+
assert.NoError(t, err)
206+
masterTree, err := gitRepo.GetTree("master")
207+
assert.NoError(t, err)
208+
wikiPath := UncycloNameToFilename(newUncycloName)
209+
entry, err := masterTree.GetTreeEntryByPath(wikiPath)
210+
assert.NoError(t, err)
211+
assert.Equal(t, wikiPath, entry.Name(), "%s not editted correctly", newUncycloName)
212+
205213
if newUncycloName != "Home" {
206-
oldPath := path.Join(repo.LocalUncycloPath(), "Home.md")
207-
assert.False(t, com.IsExist(oldPath))
214+
_, err := masterTree.GetTreeEntryByPath("Home.md")
215+
assert.Error(t, err)
208216
}
209217
}
210218
}
@@ -214,6 +222,13 @@ func TestRepository_DeleteUncycloPage(t *testing.T) {
214222
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
215223
doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
216224
assert.NoError(t, repo.DeleteUncycloPage(doer, "Home"))
217-
wikiPath := path.Join(repo.LocalUncycloPath(), "Home.md")
218-
assert.False(t, com.IsExist(wikiPath))
225+
226+
// Now need to show that the page has been added:
227+
gitRepo, err := git.OpenRepository(repo.UncycloPath())
228+
assert.NoError(t, err)
229+
masterTree, err := gitRepo.GetTree("master")
230+
assert.NoError(t, err)
231+
wikiPath := UncycloNameToFilename("Home")
232+
_, err = masterTree.GetTreeEntryByPath(wikiPath)
233+
assert.Error(t, err)
219234
}

routers/repo/branch.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ func DeleteBranchPost(ctx *context.Context) {
7171
return
7272
}
7373

74-
// Delete branch in local copy if it exists
75-
if err := ctx.Repo.Repository.DeleteLocalBranch(branchName); err != nil {
76-
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", branchName))
77-
return
78-
}
79-
8074
ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", branchName))
8175
}
8276

0 commit comments

Comments
 (0)