diff options
author | Unknwon <u@gogs.io> | 2016-08-14 23:38:35 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-08-14 23:52:24 -0700 |
commit | 54e0ada9d53c28543a436d266dc73e759cc7658b (patch) | |
tree | adafc14fd67620258077d94e96579f47111e87b1 /models/repo_editor.go | |
parent | cd89f6c5021ef129ecc4652aa620a3562ae30979 (diff) | |
download | gitea-54e0ada9d53c28543a436d266dc73e759cc7658b.tar.gz gitea-54e0ada9d53c28543a436d266dc73e759cc7658b.zip |
Web editor: improve delete file
Diffstat (limited to 'models/repo_editor.go')
-rw-r--r-- | models/repo_editor.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/models/repo_editor.go b/models/repo_editor.go index 843a58b576..070ffc3748 100644 --- a/models/repo_editor.go +++ b/models/repo_editor.go @@ -209,3 +209,63 @@ func (repo *Repository) GetDiffPreview(branch, treeName, content string) (diff * return diff, nil } + +// ________ .__ __ ___________.__.__ +// \______ \ ____ | | _____/ |_ ____ \_ _____/|__| | ____ +// | | \_/ __ \| | _/ __ \ __\/ __ \ | __) | | | _/ __ \ +// | ` \ ___/| |_\ ___/| | \ ___/ | \ | | |_\ ___/ +// /_______ /\___ >____/\___ >__| \___ > \___ / |__|____/\___ > +// \/ \/ \/ \/ \/ \/ +// + +func (repo *Repository) DeleteRepoFile(doer *User, oldCommitID, branch, treeName, message string) (err error) { + repoWorkingPool.CheckIn(com.ToStr(repo.ID)) + defer repoWorkingPool.CheckOut(com.ToStr(repo.ID)) + + localPath := repo.LocalCopyPath() + if err = discardLocalRepoBranchChanges(localPath, branch); err != nil { + return fmt.Errorf("discardLocalRepoChanges: %v", err) + } else if err = repo.UpdateLocalCopyBranch(branch); err != nil { + return fmt.Errorf("UpdateLocalCopyBranch: %v", err) + } + + filePath := path.Join(localPath, treeName) + os.Remove(filePath) + + if len(message) == 0 { + message = "Delete file '" + treeName + "'" + } + + if err = git.AddChanges(localPath, true); err != nil { + return fmt.Errorf("AddChanges: %v", err) + } else if err = git.CommitChanges(localPath, message, doer.NewGitSig()); err != nil { + return fmt.Errorf("CommitChanges: %v", err) + } else if err = git.Push(localPath, "origin", branch); err != nil { + return fmt.Errorf("Push: %v", err) + } + + gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + log.Error(4, "OpenRepository: %v", err) + return nil + } + commit, err := gitRepo.GetBranchCommit(branch) + if err != nil { + log.Error(4, "GetBranchCommit [branch: %s]: %v", branch, err) + return nil + } + + pushCommits := &PushCommits{ + Len: 1, + Commits: []*PushCommit{CommitToPushCommit(commit)}, + } + if err := CommitRepoAction(doer.ID, repo.MustOwner().ID, doer.Name, doer.Email, + repo.ID, repo.MustOwner().Name, repo.Name, git.BRANCH_PREFIX+branch, + pushCommits, oldCommitID, commit.ID.String()); err != nil { + log.Error(4, "CommitRepoAction: %v", err) + return nil + } + go HookQueue.Add(repo.ID) + + return nil +} |