delete.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.PushCommit{
  31. commit.ID.String(),
  32. commit.Message(),
  33. commit.Author.Email,
  34. commit.Author.Name,
  35. }},
  36. }
  37. oldCommitID := ctx.Repo.CommitID
  38. newCommitID := commit.ID.String()
  39. if err := models.CommitRepoAction(ctx.User.ID, ctx.Repo.Owner.ID, ctx.User.LowerName, ctx.Repo.Owner.Email,
  40. ctx.Repo.Repository.ID, ctx.Repo.Owner.LowerName, ctx.Repo.Repository.Name, "refs/heads/"+branchName, pc,
  41. oldCommitID, newCommitID); err != nil {
  42. log.Error(4, "models.CommitRepoAction(branch = %s): %v", branchName, err)
  43. }
  44. models.HookQueue.Add(ctx.Repo.Repository.ID)
  45. }
  46. ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName)
  47. }