From 193f9d4eed91d3966d9bda76f71f4d0ecaf62fc9 Mon Sep 17 00:00:00 2001 From: bigfroggit Date: Fri, 11 Sep 2026 20:04:56 +0800 Subject: [PATCH] Fix some function errors. --- pkg/commands/git_commands/svn_commands.go | 2 +- pkg/gui/controllers/helpers/refresh_helper.go | 2 +- pkg/gui/controllers/remotes_controller.go | 47 +++++++++++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/pkg/commands/git_commands/svn_commands.go b/pkg/commands/git_commands/svn_commands.go index 14e1f7f0a..9904683ab 100644 --- a/pkg/commands/git_commands/svn_commands.go +++ b/pkg/commands/git_commands/svn_commands.go @@ -387,7 +387,7 @@ func (self *SvnCommands) CheckBranchStatus(task gocui.Task, refType string) (map break } } - if isSubPath { + if !isSubPath { continue } for ref := range localRefs { diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 319c18179..d5fde5399 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1915,7 +1915,7 @@ func (self *RefreshHelper) checkSvnTagStatusAsync() { return true } relPath := strings.TrimPrefix(t.FullRefName(), refsPrefix) - return prunedSet[relPath] + return !prunedSet[relPath] }) } diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index 047fb0e5c..48b721f94 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -13,6 +13,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) type RemotesController struct { @@ -414,21 +415,49 @@ func (self *RemotesController) notGitSvnRemote() *types.DisabledReason { func (self *RemotesController) checkSvnBranchStatusAsync() { self.c.WithWaitingStatus(self.c.Tr.CheckingSvnStatus, func (task gocui.Task) error { - statuses, err := self.c.Git().Svn.CheckBranchStatus(task, "branches") + svnRemoteName := self.c.Git().Svn.GetSvnRemoteName() + + pruned, err := self.c.Git().Svn.PruneStaleRefs("branches") if err != nil { return err } + prunedSet := make(map[string]bool) + for _, p := range pruned { + prunedSet[p] = true + } + + missing, err := self.c.Git().Svn.GetMissingRefs("branches") + if err != nil { + return err + } + self.c.OnUIThread(func() error { - for _, branch := range self.c.Model().RemoteBranches { - if branch.RemoteName != "git-svn" { - continue - } - // key 为 ref 相对路径,与 RemoteBranch.Name 格式一致 - if status, ok := statuses[branch.Name]; ok { - branch.StaleStatus = status + if len(prunedSet) > 0 { + self.c.Model().RemoteBranches = lo.Filter(self.c.Model().RemoteBranches, func(b *models.RemoteBranch, _ int) bool { + if b.RemoteName != svnRemoteName { + return true + } + return !prunedSet[b.Name] + }) + } + + existingNames := make(map[string]bool) + for _, b := range self.c.Model().RemoteBranches { + if b.RemoteName == svnRemoteName { + existingNames[b.Name] = true } } - // 仅重绘视图,不 Refresh 重建模型(避免 StaleStatus 被冲掉) + for _, m := range missing { + if !existingNames[m] { + self.c.Model().RemoteBranches = append(self.c.Model().RemoteBranches, + &models.RemoteBranch{ + Name: m, + RemoteName: svnRemoteName, + StaleStatus: models.SvnBranchStatusMissing, + }) + } + } + self.c.PostRefreshUpdate(self.c.Contexts().RemoteBranches) return nil })