1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00

Merge pull request #2377 from shinhs0506/clear-staging-after-commit

This commit is contained in:
Jesse Duffield 2023-03-24 19:13:00 +11:00 committed by GitHub
commit 4780953cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 12 deletions

View File

@ -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
}
// 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 {
return gui.activateContext(contextToActivate, opts)
}
// 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 {

View File

@ -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(

View File

@ -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
}

View File

@ -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"))
},
})

View File

@ -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"))
},
})