lazygit
lazygit copied to clipboard
feat: add stash option to include untracked files
This PR adds an option to stash all changes including untracked files.
Relevant issue: https://github.com/jesseduffield/lazygit/issues/1974
Unfortunately the integration test is failing for me locally with this error:
Diff:
--- Expected
+++ Actual
@@ -19,3 +19,3 @@
git stash list:
-stash@{0}: WIP on master: 592d439 Initial commit
+stash@{0}: WIP on master: 393c632 Initial commit
But I don't know how to fix that, so I figured I'd commit it anyways and get some feedback from the reviewers.
Screenshot
The only thing I'd suggest is to move the option below all the other "stash all changes" options, i.e. the third row.
Do you know how to fix the integration test failure I posted above?
Ah, I hadn't noticed that part. I'll take a look at it first thing in the morning and get back to you.
Unless you've had some luck in the meantime? :)
Sorry haha I haven't looked at this since.
Said morning had a lot of first things
In any case, I noticed that the given stash message is never actually used, it always ends up as WIP on <branch>
.
~I presume some if goes the wrong way. Look into this if / this function.~
And let us know if you need any pointers :)
EDIT: looks like fixing that and giving the stash a message actually fixes the integration tests
Do integration tests work for you now? Can't seem to pass locally.
If it fails for you too, could you try adding a random message for stashing in the test? That seems to fix it
It's passing for me locally now.
❯ go test ./pkg/gui -run /stashIncludeUntrackedChanges
ok github.com/jesseduffield/lazygit/pkg/gui 4.589s
So in the end
handleStashSave
will only callself.c.Prompt
and it'll be up to the calling function to handle the validation
Sorry, I can't figure out how to do this. The stashFunc
function needs to check if the working tree is dirty, but I don't see how to access the IsWorkingTreeDirty
method in the stash functions, which are located in pkg/commands/git_commands/stash.go
. I can't import the FilesController
type into this file.
I'm not a Go developer so I might just be missing something here.
@ajhynes7 this can all happen within the files controller. We can remove the validation from handleStashSave like so:
func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string) error {
return self.c.Prompt(types.PromptOpts{
Title: self.c.Tr.StashChanges,
HandleConfirm: func(stashComment string) error {
self.c.LogAction(action)
if err := stashFunc(stashComment); err != nil {
return self.c.Error(err)
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
},
})
}
And then we can pull the validation up to the callsite like so:
func (self *FilesController) createStashMenu() error {
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.LcStashOptions,
Items: []*types.MenuItem{
{
Label: self.c.Tr.LcStashAllChanges,
OnPress: func() error {
if !self.helpers.WorkingTree.IsWorkingTreeDirty() {
return self.c.ErrorMsg(self.c.Tr.NoFilesToStash)
}
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges)
},
Key: 'a',
},
...
Since there's a transition to a new integration testing system, would you kindly create the test in the new framework? Just so we don't have to convert them down the road.
Here are the instructions.
There aren't any tests for stashing in the new framework, so I tried to write one for a basic stash. It's failing for me though, because the length of the StashEntries
array is still 0. Do you know how to fix that?
Hi, just checking in about this PR. Is this still under review?
Had to deal with some merge conflicts. Should be good for another review now.
Great work @ajhynes7 !
Awesome, thanks @jesseduffield and @mark2185!