-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
rename stash #2220
rename stash #2220
Conversation
1dda24b
to
bcf8e9f
Compare
bcf8e9f
to
451115f
Compare
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.
Looking good :) Can we add an integration test as well?
InitialContent: stashEntry.Name, | ||
HandleConfirm: func(response string) error { | ||
self.c.LogAction(self.c.Tr.Actions.RenameStash) | ||
output, err := self.git.Stash.Drop(stashEntry.Index) |
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 would move this logic of this HandleConfirm
callback into pkg/commands/git_commands/stash.go
because it's quite specific to git. The LogAction
and Refresh
calls can stay here
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.
Moved to stash.go.
stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) | ||
matches := stashShaPattern.FindStringSubmatch(output) | ||
stashSha := "" | ||
if len(matches) > 1 { |
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.
in what situation would we not find a match? Worth leaving a comment explaining that
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.
Normally, this regex is always matched, but added error handling
ff3b460
to
f2c11c5
Compare
pkg/commands/git_commands/stash.go
Outdated
stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) | ||
matches := stashShaPattern.FindStringSubmatch(output) | ||
if len(matches) <= 1 { | ||
return errors.New("Output of `git stash drop` is invalid") // Usually this error does not occur |
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.
not internationalized because this error never occurs
d465de5
to
a6fe332
Compare
added an integration test |
pkg/commands/git_commands/stash.go
Outdated
|
||
// `output` is in the following format: | ||
// Dropped refs/stash@{0} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd) | ||
stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) |
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 tested this out locally, and it works, but I think we should change the approach a bit. You can use git rev-parse stash@{<index>}
to obtain the hash, and I think we ought to do that for a couple of reasons:
git rev-parse
's output is never going to change, but I can imagine the output ofgit stash drop
changing. Ifgit stash drop
does change its output, we'll have just lost the user's stash which is going to make them very mad.- it spares us the complexity of regexes
So I propose we run three commands:
git rev-parse stash@{<index>}
to get the hashgit stash drop stash@{<index>}
to drop itgit stash store <hash>
to store the renamed stash entry
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.
changed that way:)
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var Rename = NewIntegrationTest(NewIntegrationTestArgs{ |
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.
perfect!
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 thing
Co-authored-by: Jesse Duffield <jessedduffield@gmail.com>
a6fe332
to
3af2686
Compare
3af2686
to
3bf2e8f
Compare
3bf2e8f
to
3103398
Compare
shell. | ||
EmptyCommit("blah"). | ||
CreateFileAndAdd("foo", "change to stash"). | ||
StashWithMessage("bar") |
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.
sorry for missing this the first time but could we add another stash entry beforehand so that when we assert that the text has been updated after renaming the stash, we're also implicitly verifying that the cursor has remained on the stash entry?
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.
only one more thing I promise ;)
updated |
Awesome work @Ryooooooga ! |
#2189
same as:
go run scripts/cheatsheet/main.go generate
)docs/Config.md
) have been updated if necessary