您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

delete.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/auth"
  8. "github.com/gogits/gogs/modules/context"
  9. "github.com/gogits/gogs/modules/log"
  10. )
  11. func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
  12. branchName := ctx.Repo.BranchName
  13. treeName := ctx.Repo.TreeName
  14. if ctx.HasError() {
  15. ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + treeName)
  16. return
  17. }
  18. if err := ctx.Repo.Repository.DeleteRepoFile(ctx.User, branchName, treeName, form.CommitSummary); err != nil {
  19. ctx.Handle(500, "DeleteRepoFile", err)
  20. return
  21. }
  22. // Was successful, so now need to call models.CommitRepoAction() with the new commitID for webhooks and watchers
  23. if branch, err := ctx.Repo.Repository.GetBranch(branchName); err != nil {
  24. log.Error(4, "repo.Repository.GetBranch(%s): %v", branchName, err)
  25. } else if commit, err := branch.GetCommit(); err != nil {
  26. log.Error(4, "branch.GetCommit(): %v", err)
  27. } else {
  28. pc := &models.PushCommits{
  29. Len: 1,
  30. Commits: []*models.PushCommit{models.CommitToPushCommit(commit)},
  31. }
  32. oldCommitID := ctx.Repo.CommitID
  33. newCommitID := commit.ID.String()
  34. if err := models.CommitRepoAction(ctx.User.ID, ctx.Repo.Owner.ID, ctx.User.LowerName, ctx.Repo.Owner.Email,
  35. ctx.Repo.Repository.ID, ctx.Repo.Owner.LowerName, ctx.Repo.Repository.Name, "refs/heads/"+branchName, pc,
  36. oldCommitID, newCommitID); err != nil {
  37. log.Error(4, "models.CommitRepoAction(branch = %s): %v", branchName, err)
  38. }
  39. models.HookQueue.Add(ctx.Repo.Repository.ID)
  40. }
  41. ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName)
  42. }