Skip to content

Hide annex branches #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: git-annex
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions models/activities/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions models/git/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 5 additions & 0 deletions models/git/branch_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
6 changes: 6 additions & 0 deletions modules/annex/annex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions routers/web/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/branch/list.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content ui repository branches">
<div role="main" aria-label="{{.Title}}" class="page-content repository branches">
{{template "repo/header" .}}
<div class="ui container">
{{template "base/alert" .}}
Expand Down