mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-23 00:39:13 +02:00
Add unambigious refs/ prefix to all stash references
Pretty basic fix, didn't seem to have any complications. I only added the refs/ prefix to the FullRefName() method to align with other similar methods, and to make this change not impact any user facing modals. Fixes: https://github.com/jesseduffield/lazygit/issues/4634 Also adds a test demonstrating that the stash show behavior is now fixed
This commit is contained in:
committed by
Stefan Haller
parent
aa23a6e2b5
commit
265557afa2
@ -32,21 +32,21 @@ func (self *StashCommands) DropNewest() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashCommands) Drop(index int) error {
|
func (self *StashCommands) Drop(index int) error {
|
||||||
cmdArgs := NewGitCmd("stash").Arg("drop", fmt.Sprintf("stash@{%d}", index)).
|
cmdArgs := NewGitCmd("stash").Arg("drop", fmt.Sprintf("refs/stash@{%d}", index)).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).Run()
|
return self.cmd.New(cmdArgs).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashCommands) Pop(index int) error {
|
func (self *StashCommands) Pop(index int) error {
|
||||||
cmdArgs := NewGitCmd("stash").Arg("pop", fmt.Sprintf("stash@{%d}", index)).
|
cmdArgs := NewGitCmd("stash").Arg("pop", fmt.Sprintf("refs/stash@{%d}", index)).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).Run()
|
return self.cmd.New(cmdArgs).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashCommands) Apply(index int) error {
|
func (self *StashCommands) Apply(index int) error {
|
||||||
cmdArgs := NewGitCmd("stash").Arg("apply", fmt.Sprintf("stash@{%d}", index)).
|
cmdArgs := NewGitCmd("stash").Arg("apply", fmt.Sprintf("refs/stash@{%d}", index)).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).Run()
|
return self.cmd.New(cmdArgs).Run()
|
||||||
@ -90,7 +90,7 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int) *oscommands.CmdObj {
|
|||||||
Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
|
Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
|
||||||
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
||||||
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
|
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
|
||||||
Arg(fmt.Sprintf("stash@{%d}", index)).
|
Arg(fmt.Sprintf("refs/stash@{%d}", index)).
|
||||||
Dir(self.repoPaths.worktreePath).
|
Dir(self.repoPaths.worktreePath).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := self.cmd.New(
|
if err := self.cmd.New(
|
||||||
NewGitCmd("stash").Arg("apply", "stash@{1}").ToArgv(),
|
NewGitCmd("stash").Arg("apply", "refs/stash@{1}").ToArgv(),
|
||||||
).Run(); err != nil {
|
).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := self.cmd.New(
|
if err := self.cmd.New(
|
||||||
NewGitCmd("stash").Arg("drop", "stash@{1}").ToArgv(),
|
NewGitCmd("stash").Arg("drop", "refs/stash@{1}").ToArgv(),
|
||||||
).Run(); err != nil {
|
).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func TestStashDrop(t *testing.T) {
|
func TestStashDrop(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "drop", "stash@{1}"}, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)\n", nil)
|
ExpectGitArgs([]string{"stash", "drop", "refs/stash@{1}"}, "Dropped refs/stash@{1} (98e9cca532c37c766107093010c72e26f2c24c04)\n", nil)
|
||||||
instance := buildStashCommands(commonDeps{runner: runner})
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, instance.Drop(1))
|
assert.NoError(t, instance.Drop(1))
|
||||||
@ -19,7 +19,7 @@ func TestStashDrop(t *testing.T) {
|
|||||||
|
|
||||||
func TestStashApply(t *testing.T) {
|
func TestStashApply(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "apply", "stash@{1}"}, "", nil)
|
ExpectGitArgs([]string{"stash", "apply", "refs/stash@{1}"}, "", nil)
|
||||||
instance := buildStashCommands(commonDeps{runner: runner})
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, instance.Apply(1))
|
assert.NoError(t, instance.Apply(1))
|
||||||
@ -28,7 +28,7 @@ func TestStashApply(t *testing.T) {
|
|||||||
|
|
||||||
func TestStashPop(t *testing.T) {
|
func TestStashPop(t *testing.T) {
|
||||||
runner := oscommands.NewFakeRunner(t).
|
runner := oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "pop", "stash@{1}"}, "", nil)
|
ExpectGitArgs([]string{"stash", "pop", "refs/stash@{1}"}, "", nil)
|
||||||
instance := buildStashCommands(commonDeps{runner: runner})
|
instance := buildStashCommands(commonDeps{runner: runner})
|
||||||
|
|
||||||
assert.NoError(t, instance.Pop(1))
|
assert.NoError(t, instance.Pop(1))
|
||||||
@ -113,7 +113,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=50%", "stash@{5}"},
|
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Show diff with custom context size",
|
testName: "Show diff with custom context size",
|
||||||
@ -121,7 +121,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize: 77,
|
contextSize: 77,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=77", "--find-renames=50%", "stash@{5}"},
|
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=77", "--find-renames=50%", "refs/stash@{5}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Show diff with custom similarity threshold",
|
testName: "Show diff with custom similarity threshold",
|
||||||
@ -129,7 +129,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 33,
|
similarityThreshold: 33,
|
||||||
ignoreWhitespace: false,
|
ignoreWhitespace: false,
|
||||||
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=33%", "stash@{5}"},
|
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=33%", "refs/stash@{5}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Default case",
|
testName: "Default case",
|
||||||
@ -137,7 +137,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
|
|||||||
contextSize: 3,
|
contextSize: 3,
|
||||||
similarityThreshold: 50,
|
similarityThreshold: 50,
|
||||||
ignoreWhitespace: true,
|
ignoreWhitespace: true,
|
||||||
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "stash@{5}"},
|
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "refs/stash@{5}"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ func TestStashRename(t *testing.T) {
|
|||||||
message: "New message",
|
message: "New message",
|
||||||
expectedHashCmd: []string{"rev-parse", "refs/stash@{3}"},
|
expectedHashCmd: []string{"rev-parse", "refs/stash@{3}"},
|
||||||
hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
|
hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
|
||||||
expectedDropCmd: []string{"stash", "drop", "stash@{3}"},
|
expectedDropCmd: []string{"stash", "drop", "refs/stash@{3}"},
|
||||||
expectedStoreCmd: []string{"stash", "store", "-m", "New message", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
|
expectedStoreCmd: []string{"stash", "store", "-m", "New message", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -186,7 +186,7 @@ func TestStashRename(t *testing.T) {
|
|||||||
message: "",
|
message: "",
|
||||||
expectedHashCmd: []string{"rev-parse", "refs/stash@{4}"},
|
expectedHashCmd: []string{"rev-parse", "refs/stash@{4}"},
|
||||||
hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
|
hashResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
|
||||||
expectedDropCmd: []string{"stash", "drop", "stash@{4}"},
|
expectedDropCmd: []string{"stash", "drop", "refs/stash@{4}"},
|
||||||
expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
|
expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ type StashEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *StashEntry) FullRefName() string {
|
func (s *StashEntry) FullRefName() string {
|
||||||
return s.RefName()
|
return "refs/" + s.RefName()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StashEntry) RefName() string {
|
func (s *StashEntry) RefName() string {
|
||||||
|
@ -187,7 +187,7 @@ func (self *StashController) postStashRefresh() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashController) handleNewBranchOffStashEntry(stashEntry *models.StashEntry) error {
|
func (self *StashController) handleNewBranchOffStashEntry(stashEntry *models.StashEntry) error {
|
||||||
return self.c.Helpers().Refs.NewBranch(stashEntry.RefName(), stashEntry.Description(), "")
|
return self.c.Helpers().Refs.NewBranch(stashEntry.FullRefName(), stashEntry.Description(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntry) error {
|
func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntry) error {
|
||||||
|
@ -12,6 +12,8 @@ var Apply = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupConfig: func(config *config.AppConfig) {},
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.EmptyCommit("initial commit")
|
shell.EmptyCommit("initial commit")
|
||||||
|
shell.NewBranch("stash")
|
||||||
|
shell.Checkout("master")
|
||||||
shell.CreateFile("file", "content")
|
shell.CreateFile("file", "content")
|
||||||
shell.GitAddAll()
|
shell.GitAddAll()
|
||||||
shell.Stash("stash one")
|
shell.Stash("stash one")
|
||||||
|
@ -12,6 +12,8 @@ var CreateBranch = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupConfig: func(config *config.AppConfig) {},
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.EmptyCommit("initial commit")
|
shell.EmptyCommit("initial commit")
|
||||||
|
shell.NewBranch("stash")
|
||||||
|
shell.Checkout("master")
|
||||||
shell.CreateFile("myfile", "content")
|
shell.CreateFile("myfile", "content")
|
||||||
shell.GitAddAll()
|
shell.GitAddAll()
|
||||||
shell.Stash("stash one")
|
shell.Stash("stash one")
|
||||||
@ -39,6 +41,7 @@ var CreateBranch = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Lines(
|
Lines(
|
||||||
Contains("new_branch").IsSelected(),
|
Contains("new_branch").IsSelected(),
|
||||||
Contains("master"),
|
Contains("master"),
|
||||||
|
Contains("stash"),
|
||||||
).
|
).
|
||||||
PressEnter()
|
PressEnter()
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ var Drop = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupConfig: func(config *config.AppConfig) {},
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.EmptyCommit("initial commit")
|
shell.EmptyCommit("initial commit")
|
||||||
|
shell.NewBranch("stash")
|
||||||
|
shell.Checkout("master")
|
||||||
shell.CreateFile("file", "content")
|
shell.CreateFile("file", "content")
|
||||||
shell.GitAddAll()
|
shell.GitAddAll()
|
||||||
shell.Stash("stash one")
|
shell.Stash("stash one")
|
||||||
|
@ -12,6 +12,8 @@ var Pop = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupConfig: func(config *config.AppConfig) {},
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.EmptyCommit("initial commit")
|
shell.EmptyCommit("initial commit")
|
||||||
|
shell.NewBranch("stash")
|
||||||
|
shell.Checkout("master")
|
||||||
shell.CreateFile("file", "content")
|
shell.CreateFile("file", "content")
|
||||||
shell.GitAddAll()
|
shell.GitAddAll()
|
||||||
shell.Stash("stash one")
|
shell.Stash("stash one")
|
||||||
|
@ -13,6 +13,8 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.
|
shell.
|
||||||
EmptyCommit("blah").
|
EmptyCommit("blah").
|
||||||
|
NewBranch("stash").
|
||||||
|
Checkout("master").
|
||||||
CreateFileAndAdd("file-1", "change to stash1").
|
CreateFileAndAdd("file-1", "change to stash1").
|
||||||
Stash("foo").
|
Stash("foo").
|
||||||
CreateFileAndAdd("file-2", "change to stash2").
|
CreateFileAndAdd("file-2", "change to stash2").
|
||||||
|
43
pkg/integration/tests/stash/show_with_branch_named_stash.go
Normal file
43
pkg/integration/tests/stash/show_with_branch_named_stash.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package stash
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ShowWithBranchNamedStash = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "View stash when there is a branch also named 'stash'",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.EmptyCommit("initial commit")
|
||||||
|
shell.CreateFile("file", "content")
|
||||||
|
shell.GitAddAll()
|
||||||
|
|
||||||
|
shell.NewBranch("stash")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Stash().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
Lines(
|
||||||
|
Contains("file"),
|
||||||
|
).
|
||||||
|
Press(keys.Files.StashAllChanges)
|
||||||
|
|
||||||
|
t.ExpectPopup().Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
|
||||||
|
|
||||||
|
t.Views().Stash().
|
||||||
|
Lines(
|
||||||
|
MatchesRegexp(`\ds .* my stashed file`),
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
|
t.Views().Stash().Focus()
|
||||||
|
t.Views().Main().ContainsLines(Equals(" file | 1 +"))
|
||||||
|
},
|
||||||
|
})
|
@ -12,6 +12,8 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupConfig: func(config *config.AppConfig) {},
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.EmptyCommit("initial commit")
|
shell.EmptyCommit("initial commit")
|
||||||
|
shell.NewBranch("stash")
|
||||||
|
shell.Checkout("master")
|
||||||
shell.CreateFile("file", "content")
|
shell.CreateFile("file", "content")
|
||||||
shell.GitAddAll()
|
shell.GitAddAll()
|
||||||
},
|
},
|
||||||
|
@ -352,6 +352,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
stash.Pop,
|
stash.Pop,
|
||||||
stash.PreventDiscardingFileChanges,
|
stash.PreventDiscardingFileChanges,
|
||||||
stash.Rename,
|
stash.Rename,
|
||||||
|
stash.ShowWithBranchNamedStash,
|
||||||
stash.Stash,
|
stash.Stash,
|
||||||
stash.StashAll,
|
stash.StashAll,
|
||||||
stash.StashAndKeepIndex,
|
stash.StashAndKeepIndex,
|
||||||
|
Reference in New Issue
Block a user