Skip to content
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

Merged
merged 6 commits into from
Oct 16, 2022
Merged

rename stash #2220

merged 6 commits into from
Oct 16, 2022

Conversation

Ryooooooga
Copy link
Contributor

@Ryooooooga Ryooooooga commented Oct 14, 2022

  • PR Description

#2189

same as:

customCommands:
  - key: r
    prompts:
      - key: Message
        type: input
        title: "Rename stash: {{.SelectedStashEntry.RefName}}"
        initialValue: "{{.SelectedStashEntry.Name}}"
    command: >-
      git stash drop {{.SelectedStashEntry.RefName}}
      | sed -E 's/.*\(([0-9a-f]+)\).*/\1/'
      | xargs git stash store -m {{.Form.Message | quote}}
    context: stash
  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go run scripts/cheatsheet/main.go generate)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • Docs (specifically docs/Config.md) have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@Ryooooooga Ryooooooga force-pushed the rename-stash branch 2 times, most recently from 1dda24b to bcf8e9f Compare October 14, 2022 14:00
@Ryooooooga Ryooooooga changed the title feat: add rename stash rename stash Oct 14, 2022
Copy link
Owner

@jesseduffield jesseduffield left a 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)
Copy link
Owner

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

Copy link
Contributor Author

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 {
Copy link
Owner

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

Copy link
Contributor Author

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

@Ryooooooga Ryooooooga force-pushed the rename-stash branch 2 times, most recently from ff3b460 to f2c11c5 Compare October 15, 2022 02:29
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
Copy link
Contributor Author

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

@Ryooooooga
Copy link
Contributor Author

added an integration test


// `output` is in the following format:
// Dropped refs/stash@{0} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd)
stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`)
Copy link
Owner

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:

  1. git rev-parse's output is never going to change, but I can imagine the output of git stash drop changing. If git stash drop does change its output, we'll have just lost the user's stash which is going to make them very mad.
  2. it spares us the complexity of regexes

So I propose we run three commands:

  1. git rev-parse stash@{<index>} to get the hash
  2. git stash drop stash@{<index>} to drop it
  3. git stash store <hash> to store the renamed stash entry

Copy link
Contributor Author

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{
Copy link
Owner

Choose a reason for hiding this comment

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

perfect!

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

one thing

Ryooooooga and others added 3 commits October 16, 2022 09:12
shell.
EmptyCommit("blah").
CreateFileAndAdd("foo", "change to stash").
StashWithMessage("bar")
Copy link
Owner

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?

Copy link
Owner

@jesseduffield jesseduffield left a 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 ;)

@Ryooooooga
Copy link
Contributor Author

updated

@jesseduffield jesseduffield merged commit 36c6462 into jesseduffield:master Oct 16, 2022
@jesseduffield
Copy link
Owner

Awesome work @Ryooooooga !

@Ryooooooga Ryooooooga deleted the rename-stash branch October 16, 2022 22:41
@strboul strboul mentioned this pull request Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants