-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add stash option to include untracked files #1980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add stash option to include untracked files #1980
Conversation
|
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 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 |
pkg/commands/git_commands/stash.go
Outdated
| } | ||
|
|
||
| func (self *StashCommands) StashUntrackedChanges(message string) error { | ||
| if err := self.cmd.New("git stash -u").Run(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant if, you could just return self.cmd.New().
I'd also suggest using the extended form of the flag, i.e. --include-untracked, just so it's easier to see what's going on.
|
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 |
jesseduffield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple things :)
pkg/commands/git_commands/stash.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func (self *StashCommands) StashUntrackedChanges(message string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StashChangedIncludingUntracked is a little more correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've changed it now to StashIncludeUntrackedChanges to be consistent with LcStashIncludeUntrackedChanges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I can change those names again if you'd prefer.
|
|
||
| func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string, errorMsg string) error { | ||
| if !self.helpers.WorkingTree.IsWorkingTreeDirty() { | ||
| if action != self.c.Tr.Actions.StashIncludeUntrackedChanges && !self.helpers.WorkingTree.IsWorkingTreeDirty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the intention behind this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method IsWorkingTreeDirty returns false if there are only untracked files, so the original expression evaluates to true and an error is raised. But I want to be able to stash these untracked files even if they're the only ones shown by git status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Rather than have conditionally logic inside this function for the sake of one use case, I say we pull the check out to the places that actually need it. This will add some duplication but I much prefer duplication to a clunky abstraction. So in the end handleStashSave will only call self.c.Prompt and it'll be up to the calling function to handle the validation
jesseduffield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one thing
|
|
||
| func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string, errorMsg string) error { | ||
| if !self.helpers.WorkingTree.IsWorkingTreeDirty() { | ||
| if action != self.c.Tr.Actions.StashIncludeUntrackedChanges && !self.helpers.WorkingTree.IsWorkingTreeDirty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Rather than have conditionally logic inside this function for the sake of one use case, I say we pull the check out to the places that actually need it. This will add some duplication but I much prefer duplication to a clunky abstraction. So in the end handleStashSave will only call self.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 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. |
9b62a86 to
e189546
Compare
|
Hi, just checking in about this PR. Is this still under review? |
jesseduffield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple things :)
pkg/integration/tests/stash/stash.go
Outdated
| assert.InMenu() | ||
|
|
||
| input.PressKeys("a") | ||
| input.Type("stash name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should assert that when 'a' is pressed, a prompt appears. Here's an example from another file:
input.PressKeys("a")
assert.InPrompt()
assert.MatchCurrentViewTitle(Equals("Enter a file name"))
input.Type("my file")|
|
||
| input.PressKeys("U") | ||
| input.Type("stash name") | ||
| input.Confirm() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
pkg/integration/tests/tests.go
Outdated
| "github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands" | ||
| "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" | ||
| "github.com/jesseduffield/lazygit/pkg/integration/tests/stash" | ||
| "github.com/jesseduffield/lazygit/pkg/utils" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've got some linting issues that need to be fixed here
|
Had to deal with some merge conflicts. Should be good for another review now. |
jesseduffield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more thing
| return self.c.PostRefreshUpdate(self.context()) | ||
| } | ||
|
|
||
| func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string, errorMsg string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove errorMsg because it's no longer used here
|
Great work @ajhynes7 ! |
|
Awesome, thanks @jesseduffield and @mark2185! |
This PR adds an option to stash all changes including untracked files.
Relevant issue: #1974
Unfortunately the integration test is failing for me locally with this error:
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