diff --git a/cmd/hook.go b/cmd/hook.go index f38fd8831b8d5..77f8add8a5064 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -446,7 +446,7 @@ Gitea or set your environment appropriately.`, "") func hookPrintResults(results []private.HookPostReceiveBranchResult) { for _, res := range results { - if !res.Message { + if !res.Message || res.Branch == "git-annex" || strings.HasPrefix(res.Branch, "synced/") { continue } diff --git a/models/activities/action.go b/models/activities/action.go index 15bd9a52acc5c..9b4bbf9193efd 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -559,6 +559,11 @@ func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder. } } + // Hide actions related to the git-annex branch + cond = cond.And(builder.Neq{"ref_name": git.BranchPrefix + "git-annex"}) + // Hide actions related to git-annex's synced/* branches + cond = cond.And(builder.Not{builder.Like{"ref_name", git.BranchPrefix + "synced/%"}}) + return cond, nil } diff --git a/models/git/branch.go b/models/git/branch.go index 6d50fb9fb6a18..72edcc37ede68 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -394,6 +394,8 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, ex err := db.GetEngine(ctx). Where("pusher_id=? AND is_deleted=?", userID, false). And("name <> ?", excludeBranchName). + And("name <> ?", "git-annex"). + And("NOT name LIKE ?", "synced/%"). And("repo_id = ?", repoID). And("commit_time >= ?", time.Now().Add(-time.Hour*6).Unix()). NotIn("name", subQuery). diff --git a/models/git/branch_list.go b/models/git/branch_list.go index b5c1301a1dc00..2004abe8c7d02 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -79,6 +79,11 @@ func (opts *FindBranchOptions) Cond() builder.Cond { cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) } + // Hide the git-annex branch if it exists + cond = cond.And(builder.Neq{"name": "git-annex"}) + // Hide synced/* branches that git-annex might have created + cond = cond.And(builder.Not{builder.Like{"name", "synced/%"}}) + if len(opts.ExcludeBranchNames) > 0 { cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames)) } diff --git a/modules/annex/annex.go b/modules/annex/annex.go index bb049d77ed686..af7fb7182dc97 100644 --- a/modules/annex/annex.go +++ b/modules/annex/annex.go @@ -152,3 +152,9 @@ func IsAnnexed(blob *git.Blob) (bool, error) { } return true, nil } + +// IsAnnexRepo determines if repo is a git-annex enabled repository +func IsAnnexRepo(repo *git.Repository) bool { + _, _, err := git.NewCommand(repo.Ctx, "annex", "info").RunStdString(&git.RunOpts{Dir: repo.Path}) + return err == nil +} diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index bc72d5f2eca17..7090f0364e596 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -15,6 +15,7 @@ import ( git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/modules/annex" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -45,6 +46,10 @@ func Branches(ctx *context.Context) { ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsBranches"] = true + if annex.IsAnnexRepo(ctx.Repo.GitRepo) { + ctx.Flash.Info("This repository is a git-annex repository, the git-annex branch as well as all synced/* branches are hidden to avoid accidental changes to or from them.", true) + } + page := ctx.FormInt("page") if page <= 1 { page = 1 diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index cec5b6fc3e62d..8314a58ad5c8c 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -1,5 +1,5 @@ {{template "base/head" .}} -