From 457cdce61d62c6d6cbe6b185d4d0dda005ecd287 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 9 Jul 2025 15:37:47 +0200 Subject: [PATCH 1/2] Fix unstable tests Now that -committerdate is the default sort order, we could get different results for the sort order of the branches list depending on whether the commits on both branches have the same committer time stamp (likely in an integration test, since git time stamps have second resolution), in which case git will fall back to alphabetical order, or not (rare, but possible), in which case master will have the newer commit and will come first. Make this stable by forcing the sort order to alphabetical. We might have more tests with this problem, we'll just have to fix them one by one as we see them fail. --- pkg/integration/tests/branch/checkout_by_name.go | 4 +++- pkg/integration/tests/branch/delete.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/integration/tests/branch/checkout_by_name.go b/pkg/integration/tests/branch/checkout_by_name.go index af06162a7..949730c30 100644 --- a/pkg/integration/tests/branch/checkout_by_name.go +++ b/pkg/integration/tests/branch/checkout_by_name.go @@ -9,7 +9,9 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ Description: "Try to checkout branch by name. Verify that it also works on the branch with the special name @.", ExtraCmdArgs: []string{}, Skip: false, - SetupConfig: func(config *config.AppConfig) {}, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical" + }, SetupRepo: func(shell *Shell) { shell. CreateNCommits(3). diff --git a/pkg/integration/tests/branch/delete.go b/pkg/integration/tests/branch/delete.go index 5da844622..2e6a19c2e 100644 --- a/pkg/integration/tests/branch/delete.go +++ b/pkg/integration/tests/branch/delete.go @@ -11,6 +11,7 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ Skip: false, SetupConfig: func(config *config.AppConfig) { config.GetUserConfig().Git.LocalBranchSortOrder = "recency" + config.GetUserConfig().Git.RemoteBranchSortOrder = "alphabetical" }, SetupRepo: func(shell *Shell) { shell. From 4981419ba95d0dc406a52c2938f28e89feba165c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 9 Jul 2025 15:12:03 +0200 Subject: [PATCH 2/2] Fix stale main view content when entering/exiting filtering view When entering filtering we would only call FocusLine, which takes care of highlighting the selected line in the commits list, but not of re-rendering the main view. HandleFocus does that. When exiting filtering, the HandleFocus call was missing entirely. The tests needed to be reworked a little bit to make this testable. --- pkg/gui/controllers/filtering_menu_action.go | 2 +- pkg/gui/controllers/helpers/mode_helper.go | 1 + .../keep_same_commit_selected_on_exit.go | 31 ++++++++++++++----- .../tests/filter_by_path/select_file.go | 15 +++++---- .../tests/filter_by_path/shared.go | 21 +++++++------ 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/pkg/gui/controllers/filtering_menu_action.go b/pkg/gui/controllers/filtering_menu_action.go index 6b67e009a..3a109a887 100644 --- a/pkg/gui/controllers/filtering_menu_action.go +++ b/pkg/gui/controllers/filtering_menu_action.go @@ -124,7 +124,7 @@ func (self *FilteringMenuAction) setFiltering() error { self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() { self.c.Contexts().LocalCommits.SetSelection(0) - self.c.Contexts().LocalCommits.FocusLine() + self.c.Contexts().LocalCommits.HandleFocus(types.OnFocusOpts{}) }}) return nil diff --git a/pkg/gui/controllers/helpers/mode_helper.go b/pkg/gui/controllers/helpers/mode_helper.go index 4af1ddf3f..f90519e4d 100644 --- a/pkg/gui/controllers/helpers/mode_helper.go +++ b/pkg/gui/controllers/helpers/mode_helper.go @@ -178,6 +178,7 @@ func (self *ModeHelper) ClearFiltering() error { // before we entered filtering self.c.Contexts().LocalCommits.SelectCommitByHash(self.c.Modes().Filtering.GetSelectedCommitHash()) } + self.c.Contexts().LocalCommits.HandleFocus(types.OnFocusOpts{}) }, }) return nil diff --git a/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go b/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go index 728a5aedf..76f35650a 100644 --- a/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go +++ b/pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go @@ -19,9 +19,9 @@ var KeepSameCommitSelectedOnExit = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains(`none of the two`).IsSelected(), - Contains(`only filterFile`), - Contains(`only otherFile`), Contains(`both files`), + Contains(`only otherFile`), + Contains(`only filterFile`), ).Press(keys.Universal.FilteringMenu). Tap(func() { t.ExpectPopup().Menu(). @@ -36,16 +36,33 @@ var KeepSameCommitSelectedOnExit = NewIntegrationTest(NewIntegrationTestArgs{ ConfirmFirstSuggestion() }). Lines( - Contains(`only filterFile`).IsSelected(), - Contains(`both files`), + Contains(`both files`).IsSelected(), + Contains(`only filterFile`), ). - SelectNextItem(). + Tap(func() { + t.Views().Main(). + ContainsLines( + Equals(" both files"), + Equals("---"), + Equals(" filterFile | 2 +-"), + Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"), + ) + }). PressEscape(). Lines( Contains(`none of the two`), - Contains(`only filterFile`), - Contains(`only otherFile`), Contains(`both files`).IsSelected(), + Contains(`only otherFile`), + Contains(`only filterFile`), + ) + + t.Views().Main(). + ContainsLines( + Equals(" both files"), + Equals("---"), + Equals(" filterFile | 2 +-"), + Equals(" otherFile | 2 +-"), + Equals(" 2 files changed, 2 insertions(+), 2 deletions(-)"), ) }, }) diff --git a/pkg/integration/tests/filter_by_path/select_file.go b/pkg/integration/tests/filter_by_path/select_file.go index 13454e1e8..a01081a22 100644 --- a/pkg/integration/tests/filter_by_path/select_file.go +++ b/pkg/integration/tests/filter_by_path/select_file.go @@ -19,22 +19,25 @@ var SelectFile = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains(`none of the two`).IsSelected(), - Contains(`only filterFile`), - Contains(`only otherFile`), Contains(`both files`), + Contains(`only otherFile`), + Contains(`only filterFile`), ). - NavigateToLine(Contains(`only filterFile`)). + NavigateToLine(Contains(`both files`)). PressEnter() - // when you click into the commit itself, you see all files from that commit t.Views().CommitFiles(). IsFocused(). Lines( - Contains(`filterFile`).IsSelected(), + Equals(`▼ /`).IsSelected(), + Equals(` M filterFile`), + Equals(` M otherFile`), ). + SelectNextItem(). Press(keys.Universal.FilteringMenu) - t.ExpectPopup().Menu().Title(Equals("Filtering")).Select(Contains("Filter by 'filterFile'")).Confirm() + t.ExpectPopup().Menu().Title(Equals("Filtering")). + Select(Contains("Filter by 'filterFile'")).Confirm() postFilterTest(t) }, diff --git a/pkg/integration/tests/filter_by_path/shared.go b/pkg/integration/tests/filter_by_path/shared.go index 6fec20a3e..dd2538a9c 100644 --- a/pkg/integration/tests/filter_by_path/shared.go +++ b/pkg/integration/tests/filter_by_path/shared.go @@ -6,14 +6,13 @@ import ( func commonSetup(shell *Shell) { shell.CreateFileAndAdd("filterFile", "original filterFile content") + shell.Commit("only filterFile") shell.CreateFileAndAdd("otherFile", "original otherFile content") - shell.Commit("both files") - - shell.UpdateFileAndAdd("otherFile", "new otherFile content") shell.Commit("only otherFile") + shell.UpdateFileAndAdd("otherFile", "new otherFile content") shell.UpdateFileAndAdd("filterFile", "new filterFile content") - shell.Commit("only filterFile") + shell.Commit("both files") shell.EmptyCommit("none of the two") } @@ -24,14 +23,18 @@ func postFilterTest(t *TestDriver) { t.Views().Commits(). IsFocused(). Lines( - Contains(`only filterFile`).IsSelected(), - Contains(`both files`), - ). - SelectNextItem() + Contains(`both files`).IsSelected(), + Contains(`only filterFile`), + ) // we only show the filtered file's changes in the main view t.Views().Main(). - Content(Contains("filterFile").DoesNotContain("otherFile")) + ContainsLines( + Equals(" both files"), + Equals("---"), + Equals(" filterFile | 2 +-"), + Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"), + ) t.Views().Commits(). PressEnter()