From 91909331b54b953ae64d030942a4787794713b9e Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 29 Jul 2023 17:30:40 +1000 Subject: [PATCH] Fix flakey worktree tests In the presentation layer, when showing branches, we'll show worktrees against branches if they're associated. But there was a race condition: if the worktree model was refreshed after the branches model, it wouldn't be used in the presentation layer when it came time to render the branches. A better solution would be to have some way of signalling that a particular context needs to be refreshed and after all the models are done being refreshed, we then refresh the contexts. This will prevent double-renders --- pkg/gui/controllers/helpers/refresh_helper.go | 6 ++++++ .../tests/worktree/detach_worktree_from_branch.go | 2 +- .../tests/worktree/remove_worktree_from_branch.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 46130231f..5682bbb1f 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -607,6 +607,12 @@ func (self *RefreshHelper) refreshWorktrees() error { self.c.Model().Worktrees = worktrees + // need to refresh branches because the branches view shows worktrees against + // branches + if err := self.c.PostRefreshUpdate(self.c.Contexts().Branches); err != nil { + return err + } + return self.c.PostRefreshUpdate(self.c.Contexts().Worktrees) } diff --git a/pkg/integration/tests/worktree/detach_worktree_from_branch.go b/pkg/integration/tests/worktree/detach_worktree_from_branch.go index 4dd3c23fd..09b3146e5 100644 --- a/pkg/integration/tests/worktree/detach_worktree_from_branch.go +++ b/pkg/integration/tests/worktree/detach_worktree_from_branch.go @@ -35,7 +35,7 @@ var DetachWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{ }). Lines( Contains("mybranch"), - Contains("newbranch").DoesNotContain("(worktree").IsSelected(), + Contains("newbranch").DoesNotContain("(worktree)").IsSelected(), ) t.Views().Worktrees(). diff --git a/pkg/integration/tests/worktree/remove_worktree_from_branch.go b/pkg/integration/tests/worktree/remove_worktree_from_branch.go index 06c729edb..2885f5669 100644 --- a/pkg/integration/tests/worktree/remove_worktree_from_branch.go +++ b/pkg/integration/tests/worktree/remove_worktree_from_branch.go @@ -46,7 +46,7 @@ var RemoveWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{ }). Lines( Contains("mybranch"), - Contains("newbranch").DoesNotContain("(worktree").IsSelected(), + Contains("newbranch").DoesNotContain("(worktree)").IsSelected(), ) t.Views().Worktrees().