summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-03-24 19:13:00 +1100
committerGitHub <noreply@github.com>2023-03-24 19:13:00 +1100
commit4780953cef543bf506d3dc68547280dae2d1481b (patch)
tree21211912fb3919f6ece2c6b27f3927028376e939
parent11bc8b87faeba22b7afac550207cf54a66801641 (diff)
parentb7c61aa883a5eddc2db6147cff9d13341b0936a8 (diff)
Merge pull request #2377 from shinhs0506/clear-staging-after-commit
-rw-r--r--pkg/gui/context.go22
-rw-r--r--pkg/gui/controllers.go4
-rw-r--r--pkg/gui/gui.go10
-rw-r--r--pkg/integration/tests/commit/staged.go8
-rw-r--r--pkg/integration/tests/commit/staged_without_hooks.go8
5 files changed, 40 insertions, 12 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 61de2d8dc..f097df807 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -52,7 +52,7 @@ func (gui *Gui) pushContext(c types.Context, opts types.OnFocusOpts) error {
return nil
}
- contextsToDeactivate := gui.pushToContextStack(c)
+ contextsToDeactivate, contextToActivate := gui.pushToContextStack(c)
for _, contextToDeactivate := range contextsToDeactivate {
if err := gui.deactivateContext(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil {
@@ -60,16 +60,28 @@ func (gui *Gui) pushContext(c types.Context, opts types.OnFocusOpts) error {
}
}
- return gui.activateContext(c, opts)
+ if contextToActivate == nil {
+ return nil
+ }
+
+ return gui.activateContext(contextToActivate, opts)
}
-// Adjusts the context stack based on the context that's being pushed and returns contexts to deactivate
-func (gui *Gui) pushToContextStack(c types.Context) []types.Context {
+// Adjusts the context stack based on the context that's being pushed and
+// returns (contexts to deactivate, context to activate)
+func (gui *Gui) pushToContextStack(c types.Context) ([]types.Context, types.Context) {
contextsToDeactivate := []types.Context{}
gui.State.ContextManager.Lock()
defer gui.State.ContextManager.Unlock()
+ if len(gui.State.ContextManager.ContextStack) > 0 &&
+ c == gui.State.ContextManager.ContextStack[len(gui.State.ContextManager.ContextStack)-1] {
+ // Context being pushed is already on top of the stack: nothing to
+ // deactivate or activate
+ return contextsToDeactivate, nil
+ }
+
if len(gui.State.ContextManager.ContextStack) == 0 {
gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack, c)
} else if c.GetKind() == types.SIDE_CONTEXT {
@@ -108,7 +120,7 @@ func (gui *Gui) pushToContextStack(c types.Context) []types.Context {
}
}
- return contextsToDeactivate
+ return contextsToDeactivate, c
}
func (gui *Gui) popContext() error {
diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go
index 80b7d9e80..4d881e586 100644
--- a/pkg/gui/controllers.go
+++ b/pkg/gui/controllers.go
@@ -9,6 +9,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
"github.com/jesseduffield/lazygit/pkg/gui/services/custom_commands"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/snake"
)
@@ -92,6 +93,9 @@ func (gui *Gui) resetControllers() {
onCommitSuccess := func() {
gui.State.savedCommitMessage = ""
+ _ = gui.c.Refresh(types.RefreshOptions{
+ Scope: []types.RefreshableView{types.STAGING},
+ })
}
commitMessageController := controllers.NewCommitMessageController(
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index a88134639..69ff10c77 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -63,9 +63,9 @@ type ContextManager struct {
sync.RWMutex
}
-func NewContextManager(initialContext types.Context) ContextManager {
+func NewContextManager() ContextManager {
return ContextManager{
- ContextStack: []types.Context{initialContext},
+ ContextStack: []types.Context{},
RWMutex: sync.RWMutex{},
}
}
@@ -298,11 +298,15 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) {
},
ScreenMode: initialScreenMode,
// TODO: put contexts in the context manager
- ContextManager: NewContextManager(initialContext),
+ ContextManager: NewContextManager(),
Contexts: contextTree,
WindowViewNameMap: initialWindowViewNameMap,
}
+ if err := gui.c.PushContext(initialContext); err != nil {
+ gui.c.Log.Error(err)
+ }
+
gui.RepoStateMap[Repo(currentDir)] = gui.State
}
diff --git a/pkg/integration/tests/commit/staged.go b/pkg/integration/tests/commit/staged.go
index 09bcf2815..f5e45995d 100644
--- a/pkg/integration/tests/commit/staged.go
+++ b/pkg/integration/tests/commit/staged.go
@@ -53,8 +53,12 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
Contains(commitMessage),
)
- t.Views().StagingSecondary().IsFocused()
+ t.Views().StagingSecondary().
+ IsEmpty()
- // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
+ t.Views().Staging().
+ IsFocused().
+ Content(Contains("+myfile content")).
+ Content(DoesNotContain("+with a second line"))
},
})
diff --git a/pkg/integration/tests/commit/staged_without_hooks.go b/pkg/integration/tests/commit/staged_without_hooks.go
index 620f712f9..dcf20d08d 100644
--- a/pkg/integration/tests/commit/staged_without_hooks.go
+++ b/pkg/integration/tests/commit/staged_without_hooks.go
@@ -53,8 +53,12 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
Contains("WIP" + commitMessage),
)
- t.Views().StagingSecondary().IsFocused()
+ t.Views().StagingSecondary().
+ IsEmpty()
- // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
+ t.Views().Staging().
+ IsFocused().
+ Content(Contains("+myfile content")).
+ Content(DoesNotContain("+with a second line"))
},
})