Skip to content

Commit 9c65c30

Browse files
committed
fix merge
1 parent 8e9e019 commit 9c65c30

File tree

5 files changed

+58
-238
lines changed

5 files changed

+58
-238
lines changed

models/repo_branch.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,6 @@ import (
1414
"github.com/Unknwon/com"
1515
)
1616

17-
// discardLocalRepoBranchChanges discards local commits/changes of
18-
// given branch to make sure it is even to remote branch.
19-
func discardLocalRepoBranchChanges(localPath, branch string) error {
20-
if !com.IsExist(localPath) {
21-
return nil
22-
}
23-
// No need to check if nothing in the repository.
24-
if !git.IsBranchExist(localPath, branch) {
25-
return nil
26-
}
27-
28-
refName := "origin/" + branch
29-
if err := git.ResetHEAD(localPath, true, refName); err != nil {
30-
return fmt.Errorf("git reset --hard %s: %v", refName, err)
31-
}
32-
return nil
33-
}
34-
35-
// DiscardLocalRepoBranchChanges discards the local repository branch changes
36-
func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
37-
return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
38-
}
39-
40-
// checkoutNewBranch checks out to a new branch from the a branch name.
41-
func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
42-
if err := git.Checkout(localPath, git.CheckoutOptions{
43-
Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
44-
Branch: newBranch,
45-
OldBranch: oldBranch,
46-
}); err != nil {
47-
return fmt.Errorf("git checkout -b %s %s: %v", newBranch, oldBranch, err)
48-
}
49-
return nil
50-
}
51-
52-
// CheckoutNewBranch checks out a new branch
53-
func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
54-
return checkoutNewBranch(repo.RepoPath(), repo.LocalCopyPath(), oldBranch, newBranch)
55-
}
56-
5717
// Branch holds the branch information
5818
type Branch struct {
5919
Path string

models/repo_editor.go

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ package models
66

77
import (
88
"fmt"
9-
"io"
109
"io/ioutil"
11-
"mime/multipart"
1210
"os"
1311
"os/exec"
1412
"path"
1513
"path/filepath"
1614
"time"
1715

1816
"github.com/Unknwon/com"
19-
gouuid "github.com/satori/go.uuid"
2017

2118
"code.gitea.io/git"
2219

@@ -325,143 +322,6 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
325322
return event, nil
326323
}
327324

328-
// ____ ___ .__ .___ ___________.___.__
329-
// | | \______ | | _________ __| _/ \_ _____/| | | ____ ______
330-
// | | /\____ \| | / _ \__ \ / __ | | __) | | | _/ __ \ / ___/
331-
// | | / | |_> > |_( <_> ) __ \_/ /_/ | | \ | | |_\ ___/ \___ \
332-
// |______/ | __/|____/\____(____ /\____ | \___ / |___|____/\___ >____ >
333-
// |__| \/ \/ \/ \/ \/
334-
//
335-
336-
// Upload represent a uploaded file to a repo to be deleted when moved
337-
type Upload struct {
338-
ID int64 `xorm:"pk autoincr"`
339-
UUID string `xorm:"uuid UNIQUE"`
340-
Name string
341-
}
342-
343-
// UploadLocalPath returns where uploads is stored in local file system based on given UUID.
344-
func UploadLocalPath(uuid string) string {
345-
return path.Join(setting.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid)
346-
}
347-
348-
// LocalPath returns where uploads are temporarily stored in local file system.
349-
func (upload *Upload) LocalPath() string {
350-
return UploadLocalPath(upload.UUID)
351-
}
352-
353-
// NewUpload creates a new upload object.
354-
func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err error) {
355-
upload := &Upload{
356-
UUID: gouuid.NewV4().String(),
357-
Name: name,
358-
}
359-
360-
localPath := upload.LocalPath()
361-
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
362-
return nil, fmt.Errorf("MkdirAll: %v", err)
363-
}
364-
365-
fw, err := os.Create(localPath)
366-
if err != nil {
367-
return nil, fmt.Errorf("Create: %v", err)
368-
}
369-
defer fw.Close()
370-
371-
if _, err = fw.Write(buf); err != nil {
372-
return nil, fmt.Errorf("Write: %v", err)
373-
} else if _, err = io.Copy(fw, file); err != nil {
374-
return nil, fmt.Errorf("Copy: %v", err)
375-
}
376-
377-
if _, err := x.Insert(upload); err != nil {
378-
return nil, err
379-
}
380-
381-
return upload, nil
382-
}
383-
384-
// GetUploadByUUID returns the Upload by UUID
385-
func GetUploadByUUID(uuid string) (*Upload, error) {
386-
upload := &Upload{UUID: uuid}
387-
has, err := x.Get(upload)
388-
if err != nil {
389-
return nil, err
390-
} else if !has {
391-
return nil, ErrUploadNotExist{0, uuid}
392-
}
393-
return upload, nil
394-
}
395-
396-
// GetUploadsByUUIDs returns multiple uploads by UUIDS
397-
func GetUploadsByUUIDs(uuids []string) ([]*Upload, error) {
398-
if len(uuids) == 0 {
399-
return []*Upload{}, nil
400-
}
401-
402-
// Silently drop invalid uuids.
403-
uploads := make([]*Upload, 0, len(uuids))
404-
return uploads, x.In("uuid", uuids).Find(&uploads)
405-
}
406-
407-
// DeleteUploads deletes multiple uploads
408-
func DeleteUploads(uploads ...*Upload) (err error) {
409-
if len(uploads) == 0 {
410-
return nil
411-
}
412-
413-
sess := x.NewSession()
414-
defer sess.Close()
415-
if err = sess.Begin(); err != nil {
416-
return err
417-
}
418-
419-
ids := make([]int64, len(uploads))
420-
for i := 0; i < len(uploads); i++ {
421-
ids[i] = uploads[i].ID
422-
}
423-
if _, err = sess.
424-
In("id", ids).
425-
Delete(new(Upload)); err != nil {
426-
return fmt.Errorf("delete uploads: %v", err)
427-
}
428-
429-
for _, upload := range uploads {
430-
localPath := upload.LocalPath()
431-
if !com.IsFile(localPath) {
432-
continue
433-
}
434-
435-
if err := os.Remove(localPath); err != nil {
436-
return fmt.Errorf("remove upload: %v", err)
437-
}
438-
}
439-
440-
return sess.Commit()
441-
}
442-
443-
// DeleteUpload delete a upload
444-
func DeleteUpload(u *Upload) error {
445-
return DeleteUploads(u)
446-
}
447-
448-
// DeleteUploadByUUID deletes a upload by UUID
449-
func DeleteUploadByUUID(uuid string) error {
450-
upload, err := GetUploadByUUID(uuid)
451-
if err != nil {
452-
if IsErrUploadNotExist(err) {
453-
return nil
454-
}
455-
return fmt.Errorf("GetUploadByUUID: %v", err)
456-
}
457-
458-
if err := DeleteUpload(upload); err != nil {
459-
return fmt.Errorf("DeleteUpload: %v", err)
460-
}
461-
462-
return nil
463-
}
464-
465325
// UploadRepoFileOptions contains the uploaded repository file options
466326
type UploadRepoFileOptions struct {
467327
LastCommitID string

modules/uploader/delete.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ type DeleteRepoFileOptions struct {
2121
}
2222

2323
// DeleteRepoFile deletes a file in the given repository
24-
func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepoFileOptions) error {
24+
func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepoFileOptions) (*models.CommitRepoEvent, error) {
2525
t, err := NewTemporaryUploadRepository(repo)
2626
defer t.Close()
2727
if err != nil {
28-
return err
28+
return nil, err
2929
}
3030
if err := t.Clone(opts.OldBranch); err != nil {
31-
return err
31+
return nil, err
3232
}
3333
if err := t.SetDefaultIndex(); err != nil {
34-
return err
34+
return nil, err
3535
}
3636

3737
filesInIndex, err := t.LsFiles(opts.TreePath)
3838
if err != nil {
39-
return fmt.Errorf("UpdateRepoFile: %v", err)
39+
return nil, fmt.Errorf("UpdateRepoFile: %v", err)
4040
}
4141

4242
inFilelist := false
@@ -46,28 +46,28 @@ func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepo
4646
}
4747
}
4848
if !inFilelist {
49-
return git.ErrNotExist{RelPath: opts.TreePath}
49+
return nil, git.ErrNotExist{RelPath: opts.TreePath}
5050
}
5151

5252
if err := t.RemoveFilesFromIndex(opts.TreePath); err != nil {
53-
return err
53+
return nil, err
5454
}
5555

5656
// Now write the tree
5757
treeHash, err := t.WriteTree()
5858
if err != nil {
59-
return err
59+
return nil, err
6060
}
6161

6262
// Now commit the tree
6363
commitHash, err := t.CommitTree(doer, treeHash, opts.Message)
6464
if err != nil {
65-
return err
65+
return nil, err
6666
}
6767

6868
// Then push this tree to NewBranch
6969
if err := t.Push(doer, commitHash, opts.NewBranch); err != nil {
70-
return err
70+
return nil, err
7171
}
7272

7373
// Simulate push event.
@@ -77,9 +77,9 @@ func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepo
7777
}
7878

7979
if err = repo.GetOwner(); err != nil {
80-
return fmt.Errorf("GetOwner: %v", err)
80+
return nil, fmt.Errorf("GetOwner: %v", err)
8181
}
82-
err = models.PushUpdate(
82+
evt, err := models.PushUpdate(
8383
opts.NewBranch,
8484
models.PushUpdateOptions{
8585
PusherID: doer.ID,
@@ -92,9 +92,9 @@ func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepo
9292
},
9393
)
9494
if err != nil {
95-
return fmt.Errorf("PushUpdate: %v", err)
95+
return nil, fmt.Errorf("PushUpdate: %v", err)
9696
}
9797

9898
// FIXME: Should we UpdateRepoIndexer(repo) here?
99-
return nil
99+
return evt, nil
100100
}

0 commit comments

Comments
 (0)