Skip to content

Fix incorrect stash diff after rename #4213

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

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/gui/controllers/stash_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr
HandleConfirm: func(response string) error {
self.c.LogAction(self.c.Tr.Actions.RenameStash)
err := self.c.Git().Stash.Rename(stashEntry.Index, response)
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
if err != nil {
_ = self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I was wondering if this is really necessary, on the assumption that if the Rename fails for some reason, then nothing should be changed. However, looking at the implementation of the Rename function it is (theoretically) possible that the operation fails after the stash was dropped, and then the save fails. It is unlikely that this happens, and it would actually be kind of bad because then your stash is gone rather than renamed, but doing something about that is out of scope for this PR I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was wondering if the refresh on error was necessary too but saw that it was introduced that way: 11316b7#diff-f92e11c5c84ff4ce46066e55444ceb7f4de7825b815670f9265b7b4e73123f28. It does look like it's there to handle the case of a failed stash store.

return err
}
self.context().SetSelection(0) // Select the renamed stash
self.context().FocusLine()
return nil
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
},
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/integration/tests/stash/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectPopup().Prompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm()
}).
SelectedLine(Contains("On master: foo baz"))

t.Views().Main().Content(Contains("file-1"))
},
})
Loading