From 3d5c53eff1a41503134d08b87ffdb5784be54eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Ri=C3=9Fe?= Date: Mon, 6 Nov 2023 16:32:53 +0100 Subject: [PATCH] git-annex: show info message for hidden branch --- modules/annex/annex.go | 6 ++++++ routers/web/repo/branch.go | 5 +++++ templates/repo/branch/list.tmpl | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) 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..ac37d0480aee0 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 is hidden to avoid accidental changes to or from it.", 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" .}} -
+
{{template "repo/header" .}}
{{template "base/alert" .}}