diff --git a/models/git/branch.go b/models/git/branch.go index 7954efb1cb7..2418c45aa19 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -208,23 +208,11 @@ func AddBranches(ctx context.Context, branches []*Branch) error { func GetDeletedBranchByID(ctx context.Context, repoID, branchID int64) (*Branch, error) { var branch Branch - has, err := db.GetEngine(ctx).ID(branchID).Get(&branch) + has, err := db.GetEngine(ctx).ID(branchID).Where("repo_id=? AND is_deleted=?", repoID, true).Get(&branch) if err != nil { return nil, err } else if !has { - return nil, ErrBranchNotExist{ - RepoID: repoID, - } - } - if branch.RepoID != repoID { - return nil, ErrBranchNotExist{ - RepoID: repoID, - } - } - if !branch.IsDeleted { - return nil, ErrBranchNotExist{ - RepoID: repoID, - } + return nil, ErrBranchNotExist{RepoID: repoID} } return &branch, nil } diff --git a/modules/git/gitcmd/pipe.go b/modules/git/gitcmd/pipe.go index d0ce3e2dc63..95b1a9205f5 100644 --- a/modules/git/gitcmd/pipe.go +++ b/modules/git/gitcmd/pipe.go @@ -9,14 +9,6 @@ import ( ) type PipeBufferReader interface { - // Read should be used in the same goroutine as command's Wait - // When Reader in one goroutine, command's Wait in another goroutine, then the command exits, the pipe will be closed: - // * If the Reader goroutine reads faster, it will read all remaining data and then get io.EOF - // * But this io.EOF doesn't mean the Reader has gotten complete data, the data might still be corrupted - // * If the Reader goroutine reads slower, it will get os.ErrClosed because the os.Pipe is closed ahead when the command exits - // - // When using 2 goroutines, no clear solution to distinguish these two cases or make Reader knows whether the data is complete - // It should avoid using Reader in a different goroutine than the command if the Read error needs to be handled. Read(p []byte) (n int, err error) Bytes() []byte } @@ -26,6 +18,15 @@ type PipeBufferWriter interface { Bytes() []byte } +// PipeReader should be used in the same goroutine as command's Wait +// When Reader in one goroutine, command's Wait in another goroutine, then the command exits, the pipe will be closed: +// * If the Reader goroutine reads faster, it will read all remaining data and then get io.EOF +// - But this io.EOF doesn't mean the Reader has gotten complete data, the data might still be corrupted +// +// * If the Reader goroutine reads slower, it will get os.ErrClosed because the os.Pipe is closed ahead when the command exits +// +// When using 2 goroutines, no clear solution to distinguish these two cases or make Reader knows whether the data is complete +// It should avoid using Reader in a different goroutine than the command if the Read error needs to be handled. type PipeReader interface { io.ReadCloser internalOnly() diff --git a/routers/web/admin/packages.go b/routers/web/admin/packages.go index e81f66d1b8a..64322ac1823 100644 --- a/routers/web/admin/packages.go +++ b/routers/web/admin/packages.go @@ -5,7 +5,6 @@ package admin import ( "net/http" - "net/url" "time" "gitea.dev/models/db" @@ -93,7 +92,7 @@ func DeletePackageVersion(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("packages.settings.delete.version.success")) - ctx.JSONRedirect(setting.AppSubURL + "/-/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type"))) + ctx.JSONRedirect("") } func CleanupExpiredData(ctx *context.Context) { diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go index 9eea7e08717..16c9bebaca3 100644 --- a/routers/web/admin/repos.go +++ b/routers/web/admin/repos.go @@ -47,10 +47,6 @@ func DeleteRepo(ctx *context.Context) { return } - if ctx.Repo != nil && ctx.Repo.GitRepo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == repo.ID { - ctx.Repo.GitRepo.Close() - } - if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil { ctx.ServerError("DeleteRepository", err) return @@ -58,7 +54,7 @@ func DeleteRepo(ctx *context.Context) { log.Trace("Repository deleted: %s", repo.FullName()) ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) - ctx.JSONRedirect(setting.AppSubURL + "/-/admin/repos?page=" + url.QueryEscape(ctx.FormString("page")) + "&sort=" + url.QueryEscape(ctx.FormString("sort"))) + ctx.JSONRedirect("") } // UnadoptedRepos lists the unadopted repositories diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 3ba0b8a869b..b3c7cc0eb67 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "net/http" - "net/url" "strings" git_model "gitea.dev/models/git" @@ -87,48 +86,31 @@ func Branches(ctx *context.Context) { ctx.HTML(http.StatusOK, tplBranch) } -// DeleteBranchPost responses for delete merged branch func DeleteBranchPost(ctx *context.Context) { - defer jsonRedirectBranches(ctx) branchName := ctx.FormString("name") - - if err := repo_service.DeleteBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName); err != nil { - switch { - case git.IsErrBranchNotExist(err): - log.Debug("DeleteBranch: Can't delete non existing branch '%s'", branchName) - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", branchName)) - case errors.Is(err, repo_service.ErrBranchIsDefault): - log.Debug("DeleteBranch: Can't delete default branch '%s'", branchName) - ctx.Flash.Error(ctx.Tr("repo.branch.default_deletion_failed", branchName)) - case errors.Is(err, git_model.ErrBranchIsProtected): - log.Debug("DeleteBranch: Can't delete protected branch '%s'", branchName) - ctx.Flash.Error(ctx.Tr("repo.branch.protected_deletion_failed", branchName)) - default: - log.Error("DeleteBranch: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", branchName)) - } - - return + err := repo_service.DeleteBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName) + switch { + case err == nil: + ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", branchName)) + ctx.JSONRedirect("") + case git.IsErrBranchNotExist(err): + ctx.JSONError(ctx.Tr("repo.branch.deletion_failed", branchName)) + case errors.Is(err, repo_service.ErrBranchIsDefault): + ctx.JSONError(ctx.Tr("repo.branch.default_deletion_failed", branchName)) + case errors.Is(err, git_model.ErrBranchIsProtected): + ctx.JSONError(ctx.Tr("repo.branch.protected_deletion_failed", branchName)) + default: + log.Error("DeleteBranch: %v", err) + ctx.JSONError(ctx.Tr("repo.branch.deletion_failed", branchName)) } - - ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", branchName)) } -// RestoreBranchPost responses for delete merged branch func RestoreBranchPost(ctx *context.Context) { - defer jsonRedirectBranches(ctx) - branchID := ctx.FormInt64("branch_id") - branchName := ctx.FormString("name") deletedBranch, err := git_model.GetDeletedBranchByID(ctx, ctx.Repo.Repository.ID, branchID) if err != nil { - log.Error("GetDeletedBranchByID: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) - return - } else if deletedBranch == nil { - log.Debug("RestoreBranch: Can't restore branch[%d] '%s', as it does not exist", branchID, branchName) - ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) + ctx.JSONErrorAuto(err) return } @@ -138,11 +120,11 @@ func RestoreBranchPost(ctx *context.Context) { }); err != nil { if strings.Contains(err.Error(), "already exists") { log.Debug("RestoreBranch: Can't restore branch '%s', since one with same name already exist", deletedBranch.Name) - ctx.Flash.Error(ctx.Tr("repo.branch.already_exists", deletedBranch.Name)) + ctx.JSONError(ctx.Tr("repo.branch.already_exists", deletedBranch.Name)) return } log.Error("RestoreBranch: CreateBranch: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name)) + ctx.JSONError(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name)) return } @@ -163,10 +145,7 @@ func RestoreBranchPost(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.branch.restore_success", deletedBranch.Name)) -} - -func jsonRedirectBranches(ctx *context.Context) { - ctx.JSONRedirect(ctx.Repo.RepoLink + "/branches?page=" + url.QueryEscape(ctx.FormString("page"))) + ctx.JSONRedirect("") } // CreateBranch creates new branch in repository diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 3d315d6df23..21eb08a34e0 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -140,6 +140,7 @@ func prepareUserNotificationsData(ctx *context.Context) { pager.RemoveParam(container.SetOf("div-only", "sequence-number")) ctx.Data["Page"] = pager + ctx.Data["PageQueryParams"] = templates.QueryBuild(pager.GetParams(), "page", page) } func filterNotificationsByRepoAccess(ctx stdCtx.Context, doer *user_model.User, notifications activities_model.NotificationList) (activities_model.NotificationList, []int, error) { diff --git a/templates/admin/packages/list.tmpl b/templates/admin/packages/list.tmpl index df322294d30..1b3bcb46177 100644 --- a/templates/admin/packages/list.tmpl +++ b/templates/admin/packages/list.tmpl @@ -51,15 +51,10 @@
- {{range .PackageDescriptors}} + {{range $pd := .PackageDescriptors}}