From b9107d5fc8ff941456b26accfefeffe0f81e8d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Donk=C3=B3?= Date: Mon, 25 Sep 2023 17:32:12 +0200 Subject: [PATCH 1/2] Support setting the similarity threshold for detecting renames --- docs/Config.md | 2 + docs/keybindings/Keybindings_en.md | 2 + docs/keybindings/Keybindings_ja.md | 2 + docs/keybindings/Keybindings_ko.md | 2 + docs/keybindings/Keybindings_nl.md | 2 + docs/keybindings/Keybindings_pl.md | 2 + docs/keybindings/Keybindings_ru.md | 2 + docs/keybindings/Keybindings_zh-CN.md | 2 + docs/keybindings/Keybindings_zh-TW.md | 2 + pkg/commands/git_commands/commit.go | 1 + pkg/commands/git_commands/commit_test.go | 88 +- pkg/commands/git_commands/file_loader.go | 10 +- pkg/commands/git_commands/file_loader_test.go | 28 +- pkg/commands/git_commands/stash.go | 1 + pkg/commands/git_commands/stash_test.go | 53 +- pkg/commands/git_commands/working_tree.go | 1 + .../git_commands/working_tree_test.go | 97 ++- pkg/config/app_config.go | 20 +- pkg/config/user_config.go | 272 +++---- pkg/gui/controllers.go | 2 + .../rename_similarity_threshold_controller.go | 100 +++ pkg/i18n/english.go | 750 +++++++++--------- .../rename_similarity_threshold_change.go | 41 + .../rename_similarity_threshold_change.go | 35 + pkg/integration/tests/test_list.go | 2 + schema/config.json | 8 + 26 files changed, 909 insertions(+), 618 deletions(-) create mode 100644 pkg/gui/controllers/rename_similarity_threshold_controller.go create mode 100644 pkg/integration/tests/diff/rename_similarity_threshold_change.go create mode 100644 pkg/integration/tests/file/rename_similarity_threshold_change.go diff --git a/docs/Config.md b/docs/Config.md index 03501e8c2fe..be579ae8bda 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -521,6 +521,8 @@ keybinding: toggleWhitespaceInDiffView: increaseContextInDiffView: '}' decreaseContextInDiffView: '{' + increaseRenameSimilarityThreshold: ) + decreaseRenameSimilarityThreshold: ( openDiffTool: status: checkForUpdate: u diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index eb88cb1829c..47ae9cfb5d7 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -14,6 +14,8 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` @ `` | View command log options | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | Push | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | Pull | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | Increase diff context size | Increase the amount of the context shown around changes in the diff view. | | `` { `` | Decrease diff context size | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | Execute custom command | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 9a146261b9a..d72096f62cd 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -14,6 +14,8 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` @ `` | コマンドログメニューを開く | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | Push | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | Pull | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | Increase diff context size | Increase the amount of the context shown around changes in the diff view. | | `` { `` | Decrease diff context size | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | カスタムコマンドを実行 | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 289f6931ff1..7c4e9c9f458 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -14,6 +14,8 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` @ `` | 명령어 로그 메뉴 열기 | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | 푸시 | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | 업데이트 | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | Diff 보기의 변경 사항 주위에 표시되는 컨텍스트의 크기를 늘리기 | Increase the amount of the context shown around changes in the diff view. | | `` { `` | Diff 보기의 변경 사항 주위에 표시되는 컨텍스트 크기 줄이기 | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | Execute custom command | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 03bf0214c6c..60cbf54e9b9 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -14,6 +14,8 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` @ `` | View command log options | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | Push | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | Pull | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | Increase diff context size | Increase the amount of the context shown around changes in the diff view. | | `` { `` | Decrease diff context size | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | Voer aangepaste commando uit | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 0336419c1e4..7d2d7e5617c 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -14,6 +14,8 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ | `` @ `` | Pokaż opcje dziennika poleceń | Pokaż opcje dla dziennika poleceń, np. pokazywanie/ukrywanie dziennika poleceń i skupienie na dzienniku poleceń. | | `` P `` | Wypchnij | Wypchnij bieżącą gałąź do jej gałęzi nadrzędnej. Jeśli nie skonfigurowano gałęzi nadrzędnej, zostaniesz poproszony o skonfigurowanie gałęzi nadrzędnej. | | `` p `` | Pociągnij | Pociągnij zmiany z zdalnego dla bieżącej gałęzi. Jeśli nie skonfigurowano gałęzi nadrzędnej, zostaniesz poproszony o skonfigurowanie gałęzi nadrzędnej. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | Zwiększ rozmiar kontekstu w widoku różnic | Zwiększ ilość kontekstu pokazywanego wokół zmian w widoku różnic. | | `` { `` | Zmniejsz rozmiar kontekstu w widoku różnic | Zmniejsz ilość kontekstu pokazywanego wokół zmian w widoku różnic. | | `` : `` | Wykonaj polecenie niestandardowe | Wyświetl monit, w którym możesz wprowadzić polecenie powłoki do wykonania. Nie należy mylić z wcześniej skonfigurowanymi poleceniami niestandardowymi. | diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index c6a784b7223..ab49f2ab370 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -14,6 +14,8 @@ _Связки клавиш_ | `` @ `` | Открыть меню журнала команд | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | Отправить изменения | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | Получить и слить изменения | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | Увеличить размер контекста, отображаемого вокруг изменений в просмотрщике сравнении | Increase the amount of the context shown around changes in the diff view. | | `` { `` | Уменьшите размер контекста, отображаемого вокруг изменений в просмотрщике сравнении | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | Выполнить пользовательскую команду | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index 8cb93e519e7..c91cdc8e874 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -14,6 +14,8 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` @ `` | 打开命令日志菜单 | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | 推送 | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | 拉取 | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | 扩大差异视图中显示的上下文范围 | Increase the amount of the context shown around changes in the diff view. | | `` { `` | 缩小差异视图中显示的上下文范围 | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | 执行自定义命令 | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index d82e3361d4f..dccba00dccf 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -14,6 +14,8 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | `` @ `` | 開啟命令記錄選單 | View options for the command log e.g. show/hide the command log and focus the command log. | | `` P `` | 推送 | Push the current branch to its upstream branch. If no upstream is configured, you will be prompted to configure an upstream branch. | | `` p `` | 拉取 | Pull changes from the remote for the current branch. If no upstream is configured, you will be prompted to configure an upstream branch. | +| `` ) `` | Increase rename similarity threshold | Increase the similarity threshold for a deletion and addition pair to be treated as a rename. | +| `` ( `` | Decrease rename similarity threshold | Decrease the similarity threshold for a deletion and addition pair to be treated as a rename. | | `` } `` | 增加差異檢視中顯示變更周圍上下文的大小 | Increase the amount of the context shown around changes in the diff view. | | `` { `` | 減小差異檢視中顯示變更周圍上下文的大小 | Decrease the amount of the context shown around changes in the diff view. | | `` : `` | 執行自訂命令 | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. | diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 517be276e88..4153dfeb909 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -271,6 +271,7 @@ func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) oscommand Arg("-p"). Arg(hash). ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). + Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)). ArgIf(filterPath != "", "--", filterPath). Dir(self.repoPaths.worktreePath). ToArgv() diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index c3708422ecb..239d7fa8f4c 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -228,54 +228,69 @@ func TestCommitCreateAmendCommit(t *testing.T) { func TestCommitShowCmdObj(t *testing.T) { type scenario struct { - testName string - filterPath string - contextSize int - ignoreWhitespace bool - extDiffCmd string - expected []string + testName string + filterPath string + contextSize int + similarityThreshold int + ignoreWhitespace bool + extDiffCmd string + expected []string } scenarios := []scenario{ { - testName: "Default case without filter path", - filterPath: "", - contextSize: 3, - ignoreWhitespace: false, - extDiffCmd: "", - expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890"}, + testName: "Default case without filter path", + filterPath: "", + contextSize: 3, + similarityThreshold: 50, + ignoreWhitespace: false, + extDiffCmd: "", + expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%"}, }, { - testName: "Default case with filter path", - filterPath: "file.txt", - contextSize: 3, - ignoreWhitespace: false, - extDiffCmd: "", - expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--", "file.txt"}, + testName: "Default case with filter path", + filterPath: "file.txt", + contextSize: 3, + similarityThreshold: 50, + ignoreWhitespace: false, + extDiffCmd: "", + expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--", "file.txt"}, }, { - testName: "Show diff with custom context size", - filterPath: "", - contextSize: 77, - ignoreWhitespace: false, - extDiffCmd: "", - expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890"}, + testName: "Show diff with custom context size", + filterPath: "", + contextSize: 77, + similarityThreshold: 50, + ignoreWhitespace: false, + extDiffCmd: "", + expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%"}, }, { - testName: "Show diff, ignoring whitespace", - filterPath: "", - contextSize: 77, - ignoreWhitespace: true, - extDiffCmd: "", - expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--ignore-all-space"}, + testName: "Show diff with custom similarity threshold", + filterPath: "", + contextSize: 3, + similarityThreshold: 33, + ignoreWhitespace: false, + extDiffCmd: "", + expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=33%"}, }, { - testName: "Show diff with external diff command", - filterPath: "", - contextSize: 3, - ignoreWhitespace: false, - extDiffCmd: "difft --color=always", - expected: []string{"-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890"}, + testName: "Show diff, ignoring whitespace", + filterPath: "", + contextSize: 77, + similarityThreshold: 50, + ignoreWhitespace: true, + extDiffCmd: "", + expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--ignore-all-space", "--find-renames=50%"}, + }, + { + testName: "Show diff with external diff command", + filterPath: "", + contextSize: 3, + similarityThreshold: 50, + ignoreWhitespace: false, + extDiffCmd: "difft --color=always", + expected: []string{"-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%"}, }, } @@ -286,6 +301,7 @@ func TestCommitShowCmdObj(t *testing.T) { appState := &config.AppState{} appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace appState.DiffContextSize = s.contextSize + appState.RenameSimilarityThreshold = s.similarityThreshold runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil) repoPaths := RepoPaths{ diff --git a/pkg/commands/git_commands/file_loader.go b/pkg/commands/git_commands/file_loader.go index 73d7fdc6482..72329543a77 100644 --- a/pkg/commands/git_commands/file_loader.go +++ b/pkg/commands/git_commands/file_loader.go @@ -100,15 +100,19 @@ type FileStatus struct { PreviousName string } -func (c *FileLoader) gitStatus(opts GitStatusOptions) ([]FileStatus, error) { +func (self *FileLoader) gitStatus(opts GitStatusOptions) ([]FileStatus, error) { cmdArgs := NewGitCmd("status"). Arg(opts.UntrackedFilesArg). Arg("--porcelain"). Arg("-z"). - ArgIf(opts.NoRenames, "--no-renames"). + ArgIfElse( + opts.NoRenames, + "--no-renames", + fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold), + ). ToArgv() - statusLines, _, err := c.cmd.New(cmdArgs).DontLog().RunWithOutputs() + statusLines, _, err := self.cmd.New(cmdArgs).DontLog().RunWithOutputs() if err != nil { return []FileStatus{}, err } diff --git a/pkg/commands/git_commands/file_loader_test.go b/pkg/commands/git_commands/file_loader_test.go index 73fac7ef4e7..5a9f15700ed 100644 --- a/pkg/commands/git_commands/file_loader_test.go +++ b/pkg/commands/git_commands/file_loader_test.go @@ -5,27 +5,31 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/config" "github.com/stretchr/testify/assert" ) func TestFileGetStatusFiles(t *testing.T) { type scenario struct { - testName string - runner oscommands.ICmdObjRunner - expectedFiles []*models.File + testName string + similarityThreshold int + runner oscommands.ICmdObjRunner + expectedFiles []*models.File } scenarios := []scenario{ { "No files found", + 50, oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z"}, "", nil), + ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"}, "", nil), []*models.File{}, }, { "Several files found", + 50, oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z"}, + ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"}, "MM file1.txt\x00A file3.txt\x00AM file2.txt\x00?? file4.txt\x00UU file5.txt", nil, ), @@ -94,8 +98,9 @@ func TestFileGetStatusFiles(t *testing.T) { }, { "File with new line char", + 50, oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z"}, "MM a\nb.txt", nil), + ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"}, "MM a\nb.txt", nil), []*models.File{ { Name: "a\nb.txt", @@ -113,8 +118,9 @@ func TestFileGetStatusFiles(t *testing.T) { }, { "Renamed files", + 50, oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z"}, + ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"}, "R after1.txt\x00before1.txt\x00RM after2.txt\x00before2.txt", nil, ), @@ -149,8 +155,9 @@ func TestFileGetStatusFiles(t *testing.T) { }, { "File with arrow in name", + 50, oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z"}, + ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"}, `?? a -> b.txt`, nil, ), @@ -175,8 +182,11 @@ func TestFileGetStatusFiles(t *testing.T) { t.Run(s.testName, func(t *testing.T) { cmd := oscommands.NewDummyCmdObjBuilder(s.runner) + appState := &config.AppState{} + appState.RenameSimilarityThreshold = s.similarityThreshold + loader := &FileLoader{ - GitCommon: buildGitCommon(commonDeps{}), + GitCommon: buildGitCommon(commonDeps{appState: appState}), cmd: cmd, config: &FakeFileLoaderConfig{showUntrackedFiles: "yes"}, getFileType: func(string) string { return "file" }, diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 5eeaa6a68c9..047985e38ed 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -87,6 +87,7 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj { Arg(fmt.Sprintf("--color=%s", self.UserConfig.Git.Paging.ColorArg)). Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)). ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). + Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)). Arg(fmt.Sprintf("stash@{%d}", index)). Dir(self.repoPaths.worktreePath). ToArgv() diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go index accd0589075..207ddb1265f 100644 --- a/pkg/commands/git_commands/stash_test.go +++ b/pkg/commands/git_commands/stash_test.go @@ -98,34 +98,46 @@ func TestStashHash(t *testing.T) { func TestStashStashEntryCmdObj(t *testing.T) { type scenario struct { - testName string - index int - contextSize int - ignoreWhitespace bool - expected []string + testName string + index int + contextSize int + similarityThreshold int + ignoreWhitespace bool + expected []string } scenarios := []scenario{ { - testName: "Default case", - index: 5, - contextSize: 3, - ignoreWhitespace: false, - expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "stash@{5}"}, + testName: "Default case", + index: 5, + contextSize: 3, + similarityThreshold: 50, + ignoreWhitespace: false, + expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--find-renames=50%", "stash@{5}"}, }, { - testName: "Show diff with custom context size", - index: 5, - contextSize: 77, - ignoreWhitespace: false, - expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=77", "stash@{5}"}, + testName: "Show diff with custom context size", + index: 5, + contextSize: 77, + similarityThreshold: 50, + ignoreWhitespace: false, + expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=77", "--find-renames=50%", "stash@{5}"}, }, { - testName: "Default case", - index: 5, - contextSize: 3, - ignoreWhitespace: true, - expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--ignore-all-space", "stash@{5}"}, + testName: "Show diff with custom similarity threshold", + index: 5, + contextSize: 3, + similarityThreshold: 33, + ignoreWhitespace: false, + expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--find-renames=33%", "stash@{5}"}, + }, + { + testName: "Default case", + index: 5, + contextSize: 3, + similarityThreshold: 50, + ignoreWhitespace: true, + expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "stash@{5}"}, }, } @@ -135,6 +147,7 @@ func TestStashStashEntryCmdObj(t *testing.T) { appState := &config.AppState{} appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace appState.DiffContextSize = s.contextSize + appState.RenameSimilarityThreshold = s.similarityThreshold repoPaths := RepoPaths{ worktreePath: "/path/to/worktree", } diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 7639dbad8ca..2364f2a68e5 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -263,6 +263,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain Arg(fmt.Sprintf("--unified=%d", contextSize)). Arg(fmt.Sprintf("--color=%s", colorArg)). ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). + Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)). ArgIf(cached, "--cached"). ArgIf(noIndex, "--no-index"). Arg("--"). diff --git a/pkg/commands/git_commands/working_tree_test.go b/pkg/commands/git_commands/working_tree_test.go index cc0ad55f5f3..a4270e732c5 100644 --- a/pkg/commands/git_commands/working_tree_test.go +++ b/pkg/commands/git_commands/working_tree_test.go @@ -205,13 +205,14 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) { func TestWorkingTreeDiff(t *testing.T) { type scenario struct { - testName string - file *models.File - plain bool - cached bool - ignoreWhitespace bool - contextSize int - runner *oscommands.FakeCmdObjRunner + testName string + file *models.File + plain bool + cached bool + ignoreWhitespace bool + contextSize int + similarityThreshold int + runner *oscommands.FakeCmdObjRunner } const expectedResult = "pretend this is an actual git diff" @@ -224,12 +225,13 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, - cached: false, - ignoreWhitespace: false, - contextSize: 3, + plain: false, + cached: false, + ignoreWhitespace: false, + contextSize: 3, + similarityThreshold: 50, runner: oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--", "test.txt"}, expectedResult, nil), + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--find-renames=50%", "--", "test.txt"}, expectedResult, nil), }, { testName: "cached", @@ -238,12 +240,13 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, - cached: true, - ignoreWhitespace: false, - contextSize: 3, + plain: false, + cached: true, + ignoreWhitespace: false, + contextSize: 3, + similarityThreshold: 50, runner: oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--cached", "--", "test.txt"}, expectedResult, nil), + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--find-renames=50%", "--cached", "--", "test.txt"}, expectedResult, nil), }, { testName: "plain", @@ -252,12 +255,13 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: true, - cached: false, - ignoreWhitespace: false, - contextSize: 3, + plain: true, + cached: false, + ignoreWhitespace: false, + contextSize: 3, + similarityThreshold: 50, runner: oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=never", "--", "test.txt"}, expectedResult, nil), + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=never", "--find-renames=50%", "--", "test.txt"}, expectedResult, nil), }, { testName: "File not tracked and file has no staged changes", @@ -266,12 +270,13 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: false, }, - plain: false, - cached: false, - ignoreWhitespace: false, - contextSize: 3, + plain: false, + cached: false, + ignoreWhitespace: false, + contextSize: 3, + similarityThreshold: 50, runner: oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--no-index", "--", "/dev/null", "test.txt"}, expectedResult, nil), + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--find-renames=50%", "--no-index", "--", "/dev/null", "test.txt"}, expectedResult, nil), }, { testName: "Default case (ignore whitespace)", @@ -280,12 +285,13 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, - cached: false, - ignoreWhitespace: true, - contextSize: 3, + plain: false, + cached: false, + ignoreWhitespace: true, + contextSize: 3, + similarityThreshold: 50, runner: oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--ignore-all-space", "--", "test.txt"}, expectedResult, nil), + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--ignore-all-space", "--find-renames=50%", "--", "test.txt"}, expectedResult, nil), }, { testName: "Show diff with custom context size", @@ -294,12 +300,28 @@ func TestWorkingTreeDiff(t *testing.T) { HasStagedChanges: false, Tracked: true, }, - plain: false, - cached: false, - ignoreWhitespace: false, - contextSize: 17, + plain: false, + cached: false, + ignoreWhitespace: false, + contextSize: 17, + similarityThreshold: 50, + runner: oscommands.NewFakeRunner(t). + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=17", "--color=always", "--find-renames=50%", "--", "test.txt"}, expectedResult, nil), + }, + { + testName: "Show diff with custom similarity threshold", + file: &models.File{ + Name: "test.txt", + HasStagedChanges: false, + Tracked: true, + }, + plain: false, + cached: false, + ignoreWhitespace: false, + contextSize: 3, + similarityThreshold: 33, runner: oscommands.NewFakeRunner(t). - ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=17", "--color=always", "--", "test.txt"}, expectedResult, nil), + ExpectGitArgs([]string{"-C", "/path/to/worktree", "diff", "--no-ext-diff", "--submodule", "--unified=3", "--color=always", "--find-renames=33%", "--", "test.txt"}, expectedResult, nil), }, } @@ -309,6 +331,7 @@ func TestWorkingTreeDiff(t *testing.T) { appState := &config.AppState{} appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace appState.DiffContextSize = s.contextSize + appState.RenameSimilarityThreshold = s.similarityThreshold repoPaths := RepoPaths{ worktreePath: "/path/to/worktree", } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 97f32688ec9..19febf9a637 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -370,6 +370,7 @@ type AppState struct { HideCommandLog bool IgnoreWhitespaceInDiffView bool DiffContextSize int + RenameSimilarityThreshold int LocalBranchSortOrder string RemoteBranchSortOrder string @@ -385,15 +386,16 @@ type AppState struct { func getDefaultAppState() *AppState { return &AppState{ - LastUpdateCheck: 0, - RecentRepos: []string{}, - StartupPopupVersion: 0, - LastVersion: "", - DiffContextSize: 3, - LocalBranchSortOrder: "recency", - RemoteBranchSortOrder: "alphabetical", - GitLogOrder: "", // should be "topo-order" eventually - GitLogShowGraph: "", // should be "always" eventually + LastUpdateCheck: 0, + RecentRepos: []string{}, + StartupPopupVersion: 0, + LastVersion: "", + DiffContextSize: 3, + RenameSimilarityThreshold: 50, + LocalBranchSortOrder: "recency", + RemoteBranchSortOrder: "alphabetical", + GitLogOrder: "", // should be "topo-order" eventually + GitLogShowGraph: "", // should be "always" eventually } } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index fbf513ea6f1..d08e4fda476 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -341,73 +341,75 @@ type KeybindingConfig struct { // damn looks like we have some inconsistencies here with -alt and -alt1 type KeybindingUniversalConfig struct { - Quit string `yaml:"quit"` - QuitAlt1 string `yaml:"quit-alt1"` - Return string `yaml:"return"` - QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"` - TogglePanel string `yaml:"togglePanel"` - PrevItem string `yaml:"prevItem"` - NextItem string `yaml:"nextItem"` - PrevItemAlt string `yaml:"prevItem-alt"` - NextItemAlt string `yaml:"nextItem-alt"` - PrevPage string `yaml:"prevPage"` - NextPage string `yaml:"nextPage"` - ScrollLeft string `yaml:"scrollLeft"` - ScrollRight string `yaml:"scrollRight"` - GotoTop string `yaml:"gotoTop"` - GotoBottom string `yaml:"gotoBottom"` - ToggleRangeSelect string `yaml:"toggleRangeSelect"` - RangeSelectDown string `yaml:"rangeSelectDown"` - RangeSelectUp string `yaml:"rangeSelectUp"` - PrevBlock string `yaml:"prevBlock"` - NextBlock string `yaml:"nextBlock"` - PrevBlockAlt string `yaml:"prevBlock-alt"` - NextBlockAlt string `yaml:"nextBlock-alt"` - NextBlockAlt2 string `yaml:"nextBlock-alt2"` - PrevBlockAlt2 string `yaml:"prevBlock-alt2"` - JumpToBlock []string `yaml:"jumpToBlock"` - NextMatch string `yaml:"nextMatch"` - PrevMatch string `yaml:"prevMatch"` - StartSearch string `yaml:"startSearch"` - OptionMenu string `yaml:"optionMenu"` - OptionMenuAlt1 string `yaml:"optionMenu-alt1"` - Select string `yaml:"select"` - GoInto string `yaml:"goInto"` - Confirm string `yaml:"confirm"` - ConfirmInEditor string `yaml:"confirmInEditor"` - Remove string `yaml:"remove"` - New string `yaml:"new"` - Edit string `yaml:"edit"` - OpenFile string `yaml:"openFile"` - ScrollUpMain string `yaml:"scrollUpMain"` - ScrollDownMain string `yaml:"scrollDownMain"` - ScrollUpMainAlt1 string `yaml:"scrollUpMain-alt1"` - ScrollDownMainAlt1 string `yaml:"scrollDownMain-alt1"` - ScrollUpMainAlt2 string `yaml:"scrollUpMain-alt2"` - ScrollDownMainAlt2 string `yaml:"scrollDownMain-alt2"` - ExecuteCustomCommand string `yaml:"executeCustomCommand"` - CreateRebaseOptionsMenu string `yaml:"createRebaseOptionsMenu"` - Push string `yaml:"pushFiles"` // 'Files' appended for legacy reasons - Pull string `yaml:"pullFiles"` // 'Files' appended for legacy reasons - Refresh string `yaml:"refresh"` - CreatePatchOptionsMenu string `yaml:"createPatchOptionsMenu"` - NextTab string `yaml:"nextTab"` - PrevTab string `yaml:"prevTab"` - NextScreenMode string `yaml:"nextScreenMode"` - PrevScreenMode string `yaml:"prevScreenMode"` - Undo string `yaml:"undo"` - Redo string `yaml:"redo"` - FilteringMenu string `yaml:"filteringMenu"` - DiffingMenu string `yaml:"diffingMenu"` - DiffingMenuAlt string `yaml:"diffingMenu-alt"` - CopyToClipboard string `yaml:"copyToClipboard"` - OpenRecentRepos string `yaml:"openRecentRepos"` - SubmitEditorText string `yaml:"submitEditorText"` - ExtrasMenu string `yaml:"extrasMenu"` - ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"` - IncreaseContextInDiffView string `yaml:"increaseContextInDiffView"` - DecreaseContextInDiffView string `yaml:"decreaseContextInDiffView"` - OpenDiffTool string `yaml:"openDiffTool"` + Quit string `yaml:"quit"` + QuitAlt1 string `yaml:"quit-alt1"` + Return string `yaml:"return"` + QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"` + TogglePanel string `yaml:"togglePanel"` + PrevItem string `yaml:"prevItem"` + NextItem string `yaml:"nextItem"` + PrevItemAlt string `yaml:"prevItem-alt"` + NextItemAlt string `yaml:"nextItem-alt"` + PrevPage string `yaml:"prevPage"` + NextPage string `yaml:"nextPage"` + ScrollLeft string `yaml:"scrollLeft"` + ScrollRight string `yaml:"scrollRight"` + GotoTop string `yaml:"gotoTop"` + GotoBottom string `yaml:"gotoBottom"` + ToggleRangeSelect string `yaml:"toggleRangeSelect"` + RangeSelectDown string `yaml:"rangeSelectDown"` + RangeSelectUp string `yaml:"rangeSelectUp"` + PrevBlock string `yaml:"prevBlock"` + NextBlock string `yaml:"nextBlock"` + PrevBlockAlt string `yaml:"prevBlock-alt"` + NextBlockAlt string `yaml:"nextBlock-alt"` + NextBlockAlt2 string `yaml:"nextBlock-alt2"` + PrevBlockAlt2 string `yaml:"prevBlock-alt2"` + JumpToBlock []string `yaml:"jumpToBlock"` + NextMatch string `yaml:"nextMatch"` + PrevMatch string `yaml:"prevMatch"` + StartSearch string `yaml:"startSearch"` + OptionMenu string `yaml:"optionMenu"` + OptionMenuAlt1 string `yaml:"optionMenu-alt1"` + Select string `yaml:"select"` + GoInto string `yaml:"goInto"` + Confirm string `yaml:"confirm"` + ConfirmInEditor string `yaml:"confirmInEditor"` + Remove string `yaml:"remove"` + New string `yaml:"new"` + Edit string `yaml:"edit"` + OpenFile string `yaml:"openFile"` + ScrollUpMain string `yaml:"scrollUpMain"` + ScrollDownMain string `yaml:"scrollDownMain"` + ScrollUpMainAlt1 string `yaml:"scrollUpMain-alt1"` + ScrollDownMainAlt1 string `yaml:"scrollDownMain-alt1"` + ScrollUpMainAlt2 string `yaml:"scrollUpMain-alt2"` + ScrollDownMainAlt2 string `yaml:"scrollDownMain-alt2"` + ExecuteCustomCommand string `yaml:"executeCustomCommand"` + CreateRebaseOptionsMenu string `yaml:"createRebaseOptionsMenu"` + Push string `yaml:"pushFiles"` // 'Files' appended for legacy reasons + Pull string `yaml:"pullFiles"` // 'Files' appended for legacy reasons + Refresh string `yaml:"refresh"` + CreatePatchOptionsMenu string `yaml:"createPatchOptionsMenu"` + NextTab string `yaml:"nextTab"` + PrevTab string `yaml:"prevTab"` + NextScreenMode string `yaml:"nextScreenMode"` + PrevScreenMode string `yaml:"prevScreenMode"` + Undo string `yaml:"undo"` + Redo string `yaml:"redo"` + FilteringMenu string `yaml:"filteringMenu"` + DiffingMenu string `yaml:"diffingMenu"` + DiffingMenuAlt string `yaml:"diffingMenu-alt"` + CopyToClipboard string `yaml:"copyToClipboard"` + OpenRecentRepos string `yaml:"openRecentRepos"` + SubmitEditorText string `yaml:"submitEditorText"` + ExtrasMenu string `yaml:"extrasMenu"` + ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"` + IncreaseContextInDiffView string `yaml:"increaseContextInDiffView"` + DecreaseContextInDiffView string `yaml:"decreaseContextInDiffView"` + IncreaseRenameSimilarityThreshold string `yaml:"increaseRenameSimilarityThreshold"` + DecreaseRenameSimilarityThreshold string `yaml:"decreaseRenameSimilarityThreshold"` + OpenDiffTool string `yaml:"openDiffTool"` } type KeybindingStatusConfig struct { @@ -777,73 +779,75 @@ func GetDefaultConfig() *UserConfig { PromptToReturnFromSubprocess: true, Keybinding: KeybindingConfig{ Universal: KeybindingUniversalConfig{ - Quit: "q", - QuitAlt1: "", - Return: "", - QuitWithoutChangingDirectory: "Q", - TogglePanel: "", - PrevItem: "", - NextItem: "", - PrevItemAlt: "k", - NextItemAlt: "j", - PrevPage: ",", - NextPage: ".", - ScrollLeft: "H", - ScrollRight: "L", - GotoTop: "<", - GotoBottom: ">", - ToggleRangeSelect: "v", - RangeSelectDown: "", - RangeSelectUp: "", - PrevBlock: "", - NextBlock: "", - PrevBlockAlt: "h", - NextBlockAlt: "l", - PrevBlockAlt2: "", - NextBlockAlt2: "", - JumpToBlock: []string{"1", "2", "3", "4", "5"}, - NextMatch: "n", - PrevMatch: "N", - StartSearch: "/", - OptionMenu: "", - OptionMenuAlt1: "?", - Select: "", - GoInto: "", - Confirm: "", - ConfirmInEditor: "", - Remove: "d", - New: "n", - Edit: "e", - OpenFile: "o", - OpenRecentRepos: "", - ScrollUpMain: "", - ScrollDownMain: "", - ScrollUpMainAlt1: "K", - ScrollDownMainAlt1: "J", - ScrollUpMainAlt2: "", - ScrollDownMainAlt2: "", - ExecuteCustomCommand: ":", - CreateRebaseOptionsMenu: "m", - Push: "P", - Pull: "p", - Refresh: "R", - CreatePatchOptionsMenu: "", - NextTab: "]", - PrevTab: "[", - NextScreenMode: "+", - PrevScreenMode: "_", - Undo: "z", - Redo: "", - FilteringMenu: "", - DiffingMenu: "W", - DiffingMenuAlt: "", - CopyToClipboard: "", - SubmitEditorText: "", - ExtrasMenu: "@", - ToggleWhitespaceInDiffView: "", - IncreaseContextInDiffView: "}", - DecreaseContextInDiffView: "{", - OpenDiffTool: "", + Quit: "q", + QuitAlt1: "", + Return: "", + QuitWithoutChangingDirectory: "Q", + TogglePanel: "", + PrevItem: "", + NextItem: "", + PrevItemAlt: "k", + NextItemAlt: "j", + PrevPage: ",", + NextPage: ".", + ScrollLeft: "H", + ScrollRight: "L", + GotoTop: "<", + GotoBottom: ">", + ToggleRangeSelect: "v", + RangeSelectDown: "", + RangeSelectUp: "", + PrevBlock: "", + NextBlock: "", + PrevBlockAlt: "h", + NextBlockAlt: "l", + PrevBlockAlt2: "", + NextBlockAlt2: "", + JumpToBlock: []string{"1", "2", "3", "4", "5"}, + NextMatch: "n", + PrevMatch: "N", + StartSearch: "/", + OptionMenu: "", + OptionMenuAlt1: "?", + Select: "", + GoInto: "", + Confirm: "", + ConfirmInEditor: "", + Remove: "d", + New: "n", + Edit: "e", + OpenFile: "o", + OpenRecentRepos: "", + ScrollUpMain: "", + ScrollDownMain: "", + ScrollUpMainAlt1: "K", + ScrollDownMainAlt1: "J", + ScrollUpMainAlt2: "", + ScrollDownMainAlt2: "", + ExecuteCustomCommand: ":", + CreateRebaseOptionsMenu: "m", + Push: "P", + Pull: "p", + Refresh: "R", + CreatePatchOptionsMenu: "", + NextTab: "]", + PrevTab: "[", + NextScreenMode: "+", + PrevScreenMode: "_", + Undo: "z", + Redo: "", + FilteringMenu: "", + DiffingMenu: "W", + DiffingMenuAlt: "", + CopyToClipboard: "", + SubmitEditorText: "", + ExtrasMenu: "@", + ToggleWhitespaceInDiffView: "", + IncreaseContextInDiffView: "}", + DecreaseContextInDiffView: "{", + IncreaseRenameSimilarityThreshold: ")", + DecreaseRenameSimilarityThreshold: "(", + OpenDiffTool: "", }, Status: KeybindingStatusConfig{ CheckForUpdate: "u", diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index ba39fef5a45..277098f3789 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -179,6 +179,7 @@ func (gui *Gui) resetHelpersAndControllers() { undoController := controllers.NewUndoController(common) globalController := controllers.NewGlobalController(common) contextLinesController := controllers.NewContextLinesController(common) + renameSimilarityThresholdController := controllers.NewRenameSimilarityThresholdController(common) verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common, &gui.viewBufferManagerMap) branchesController := controllers.NewBranchesController(common) @@ -383,6 +384,7 @@ func (gui *Gui) resetHelpersAndControllers() { undoController, globalController, contextLinesController, + renameSimilarityThresholdController, jumpToSideWindowController, syncController, ) diff --git a/pkg/gui/controllers/rename_similarity_threshold_controller.go b/pkg/gui/controllers/rename_similarity_threshold_controller.go new file mode 100644 index 00000000000..0b154aa3665 --- /dev/null +++ b/pkg/gui/controllers/rename_similarity_threshold_controller.go @@ -0,0 +1,100 @@ +package controllers + +import ( + "fmt" + + "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/samber/lo" +) + +// This controller lets you change the similarity threshold for detecting renames. + +var CONTEXT_KEYS_SHOWING_RENAMES = []types.ContextKey{ + context.FILES_CONTEXT_KEY, + context.SUB_COMMITS_CONTEXT_KEY, + context.LOCAL_COMMITS_CONTEXT_KEY, + context.STASH_CONTEXT_KEY, +} + +type RenameSimilarityThresholdController struct { + baseController + c *ControllerCommon +} + +var _ types.IController = &RenameSimilarityThresholdController{} + +func NewRenameSimilarityThresholdController( + common *ControllerCommon, +) *RenameSimilarityThresholdController { + return &RenameSimilarityThresholdController{ + baseController: baseController{}, + c: common, + } +} + +func (self *RenameSimilarityThresholdController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + bindings := []*types.Binding{ + { + Key: opts.GetKey(opts.Config.Universal.IncreaseRenameSimilarityThreshold), + Handler: self.Increase, + Description: self.c.Tr.IncreaseRenameSimilarityThreshold, + Tooltip: self.c.Tr.IncreaseRenameSimilarityThresholdTooltip, + }, + { + Key: opts.GetKey(opts.Config.Universal.DecreaseRenameSimilarityThreshold), + Handler: self.Decrease, + Description: self.c.Tr.DecreaseRenameSimilarityThreshold, + Tooltip: self.c.Tr.DecreaseRenameSimilarityThresholdTooltip, + }, + } + + return bindings +} + +func (self *RenameSimilarityThresholdController) Context() types.Context { + return nil +} + +func (self *RenameSimilarityThresholdController) Increase() error { + old_size := self.c.AppState.RenameSimilarityThreshold + + if self.isShowingRenames() && old_size < 100 { + self.c.AppState.RenameSimilarityThreshold = min(100, old_size+5) + return self.applyChange() + } + + return nil +} + +func (self *RenameSimilarityThresholdController) Decrease() error { + old_size := self.c.AppState.RenameSimilarityThreshold + + if self.isShowingRenames() && old_size > 5 { + self.c.AppState.RenameSimilarityThreshold = max(5, old_size-5) + return self.applyChange() + } + + return nil +} + +func (self *RenameSimilarityThresholdController) applyChange() error { + self.c.Toast(fmt.Sprintf(self.c.Tr.RenameSimilarityThresholdChanged, self.c.AppState.RenameSimilarityThreshold)) + self.c.SaveAppStateAndLogError() + + currentContext := self.c.CurrentStaticContext() + switch currentContext.GetKey() { + // we make an exception for our files context, because it actually need to refresh its state afterwards. + case context.FILES_CONTEXT_KEY: + return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}}) + default: + return currentContext.HandleRenderToMain() + } +} + +func (self *RenameSimilarityThresholdController) isShowingRenames() bool { + return lo.Contains( + CONTEXT_KEYS_SHOWING_RENAMES, + self.c.CurrentStaticContext().GetKey(), + ) +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index d4c65620209..296239ddecd 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -642,163 +642,168 @@ type TranslationSet struct { NavigationTitle string SuggestionsCheatsheetTitle string // Unlike the cheatsheet title above, the real suggestions title has a little message saying press tab to focus - SuggestionsTitle string - SuggestionsSubtitle string - ExtrasTitle string - PushingTagStatus string - PullRequestURLCopiedToClipboard string - CommitDiffCopiedToClipboard string - CommitURLCopiedToClipboard string - CommitMessageCopiedToClipboard string - CommitSubjectCopiedToClipboard string - CommitAuthorCopiedToClipboard string - PatchCopiedToClipboard string - CopiedToClipboard string - ErrCannotEditDirectory string - ErrStageDirWithInlineMergeConflicts string - ErrRepositoryMovedOrDeleted string - ErrWorktreeMovedOrRemoved string - CommandLog string - ToggleShowCommandLog string - FocusCommandLog string - CommandLogHeader string - RandomTip string - SelectParentCommitForMerge string - ToggleWhitespaceInDiffView string - ToggleWhitespaceInDiffViewTooltip string - IgnoreWhitespaceDiffViewSubTitle string - IgnoreWhitespaceNotSupportedHere string - IncreaseContextInDiffView string - IncreaseContextInDiffViewTooltip string - DecreaseContextInDiffView string - DecreaseContextInDiffViewTooltip string - DiffContextSizeChanged string - CreatePullRequestOptions string - DefaultBranch string - SelectBranch string - CreatePullRequest string - SelectConfigFile string - NoConfigFileFoundErr string - LoadingFileSuggestions string - LoadingCommits string - MustSpecifyOriginError string - GitOutput string - GitCommandFailed string - AbortTitle string - AbortPrompt string - OpenLogMenu string - OpenLogMenuTooltip string - LogMenuTitle string - ToggleShowGitGraphAll string - ShowGitGraph string - SortOrder string - SortAlphabetical string - SortByDate string - SortByRecency string - SortBasedOnReflog string - SortCommits string - CantChangeContextSizeError string - OpenCommitInBrowser string - ViewBisectOptions string - ConfirmRevertCommit string - RewordInEditorTitle string - RewordInEditorPrompt string - CheckoutPrompt string - HardResetAutostashPrompt string - UpstreamGone string - NukeDescription string - DiscardStagedChangesDescription string - EmptyOutput string - Patch string - CustomPatch string - CommitsCopied string - CommitCopied string - ResetPatch string - ResetPatchTooltip string - ApplyPatch string - ApplyPatchTooltip string - ApplyPatchInReverse string - ApplyPatchInReverseTooltip string - RemovePatchFromOriginalCommit string - RemovePatchFromOriginalCommitTooltip string - MovePatchOutIntoIndex string - MovePatchOutIntoIndexTooltip string - MovePatchIntoNewCommit string - MovePatchIntoNewCommitTooltip string - MovePatchToSelectedCommit string - MovePatchToSelectedCommitTooltip string - CopyPatchToClipboard string - NoMatchesFor string - MatchesFor string - SearchKeybindings string - SearchPrefix string - FilterPrefix string - ExitSearchMode string - ExitTextFilterMode string - Switch string - SwitchToWorktree string - SwitchToWorktreeTooltip string - AlreadyCheckedOutByWorktree string - BranchCheckedOutByWorktree string - DetachWorktreeTooltip string - Switching string - RemoveWorktree string - RemoveWorktreeTitle string - DetachWorktree string - DetachingWorktree string - WorktreesTitle string - WorktreeTitle string - RemoveWorktreePrompt string - ForceRemoveWorktreePrompt string - RemovingWorktree string - AddingWorktree string - CantDeleteCurrentWorktree string - AlreadyInWorktree string - CantDeleteMainWorktree string - NoWorktreesThisRepo string - MissingWorktree string - MainWorktree string - NewWorktree string - NewWorktreePath string - NewWorktreeBase string - RemoveWorktreeTooltip string - BranchNameCannotBeBlank string - NewBranchName string - NewBranchNameLeaveBlank string - ViewWorktreeOptions string - CreateWorktreeFrom string - CreateWorktreeFromDetached string - LcWorktree string - ChangingDirectoryTo string - Name string - Branch string - Path string - MarkedBaseCommitStatus string - MarkAsBaseCommit string - MarkAsBaseCommitTooltip string - MarkedCommitMarker string - PleaseGoToURL string - NoCopiedCommits string - DisabledMenuItemPrefix string - QuickStartInteractiveRebase string - QuickStartInteractiveRebaseTooltip string - CannotQuickStartInteractiveRebase string - ToggleRangeSelect string - RangeSelectUp string - RangeSelectDown string - RangeSelectNotSupported string - NoItemSelected string - SelectedItemIsNotABranch string - SelectedItemDoesNotHaveFiles string - RangeSelectNotSupportedForSubmodules string - OldCherryPickKeyWarning string - CommandDoesNotSupportOpeningInEditor string - Actions Actions - Bisect Bisect - Log Log - BreakingChangesTitle string - BreakingChangesMessage string - BreakingChangesByVersion map[string]string + SuggestionsTitle string + SuggestionsSubtitle string + ExtrasTitle string + PushingTagStatus string + PullRequestURLCopiedToClipboard string + CommitDiffCopiedToClipboard string + CommitURLCopiedToClipboard string + CommitMessageCopiedToClipboard string + CommitSubjectCopiedToClipboard string + CommitAuthorCopiedToClipboard string + PatchCopiedToClipboard string + CopiedToClipboard string + ErrCannotEditDirectory string + ErrStageDirWithInlineMergeConflicts string + ErrRepositoryMovedOrDeleted string + ErrWorktreeMovedOrRemoved string + CommandLog string + ToggleShowCommandLog string + FocusCommandLog string + CommandLogHeader string + RandomTip string + SelectParentCommitForMerge string + ToggleWhitespaceInDiffView string + ToggleWhitespaceInDiffViewTooltip string + IgnoreWhitespaceDiffViewSubTitle string + IgnoreWhitespaceNotSupportedHere string + IncreaseContextInDiffView string + IncreaseContextInDiffViewTooltip string + DecreaseContextInDiffView string + DecreaseContextInDiffViewTooltip string + DiffContextSizeChanged string + IncreaseRenameSimilarityThreshold string + IncreaseRenameSimilarityThresholdTooltip string + DecreaseRenameSimilarityThreshold string + DecreaseRenameSimilarityThresholdTooltip string + RenameSimilarityThresholdChanged string + CreatePullRequestOptions string + DefaultBranch string + SelectBranch string + CreatePullRequest string + SelectConfigFile string + NoConfigFileFoundErr string + LoadingFileSuggestions string + LoadingCommits string + MustSpecifyOriginError string + GitOutput string + GitCommandFailed string + AbortTitle string + AbortPrompt string + OpenLogMenu string + OpenLogMenuTooltip string + LogMenuTitle string + ToggleShowGitGraphAll string + ShowGitGraph string + SortOrder string + SortAlphabetical string + SortByDate string + SortByRecency string + SortBasedOnReflog string + SortCommits string + CantChangeContextSizeError string + OpenCommitInBrowser string + ViewBisectOptions string + ConfirmRevertCommit string + RewordInEditorTitle string + RewordInEditorPrompt string + CheckoutPrompt string + HardResetAutostashPrompt string + UpstreamGone string + NukeDescription string + DiscardStagedChangesDescription string + EmptyOutput string + Patch string + CustomPatch string + CommitsCopied string + CommitCopied string + ResetPatch string + ResetPatchTooltip string + ApplyPatch string + ApplyPatchTooltip string + ApplyPatchInReverse string + ApplyPatchInReverseTooltip string + RemovePatchFromOriginalCommit string + RemovePatchFromOriginalCommitTooltip string + MovePatchOutIntoIndex string + MovePatchOutIntoIndexTooltip string + MovePatchIntoNewCommit string + MovePatchIntoNewCommitTooltip string + MovePatchToSelectedCommit string + MovePatchToSelectedCommitTooltip string + CopyPatchToClipboard string + NoMatchesFor string + MatchesFor string + SearchKeybindings string + SearchPrefix string + FilterPrefix string + ExitSearchMode string + ExitTextFilterMode string + Switch string + SwitchToWorktree string + SwitchToWorktreeTooltip string + AlreadyCheckedOutByWorktree string + BranchCheckedOutByWorktree string + DetachWorktreeTooltip string + Switching string + RemoveWorktree string + RemoveWorktreeTitle string + DetachWorktree string + DetachingWorktree string + WorktreesTitle string + WorktreeTitle string + RemoveWorktreePrompt string + ForceRemoveWorktreePrompt string + RemovingWorktree string + AddingWorktree string + CantDeleteCurrentWorktree string + AlreadyInWorktree string + CantDeleteMainWorktree string + NoWorktreesThisRepo string + MissingWorktree string + MainWorktree string + NewWorktree string + NewWorktreePath string + NewWorktreeBase string + RemoveWorktreeTooltip string + BranchNameCannotBeBlank string + NewBranchName string + NewBranchNameLeaveBlank string + ViewWorktreeOptions string + CreateWorktreeFrom string + CreateWorktreeFromDetached string + LcWorktree string + ChangingDirectoryTo string + Name string + Branch string + Path string + MarkedBaseCommitStatus string + MarkAsBaseCommit string + MarkAsBaseCommitTooltip string + MarkedCommitMarker string + PleaseGoToURL string + NoCopiedCommits string + DisabledMenuItemPrefix string + QuickStartInteractiveRebase string + QuickStartInteractiveRebaseTooltip string + CannotQuickStartInteractiveRebase string + ToggleRangeSelect string + RangeSelectUp string + RangeSelectDown string + RangeSelectNotSupported string + NoItemSelected string + SelectedItemIsNotABranch string + SelectedItemDoesNotHaveFiles string + RangeSelectNotSupportedForSubmodules string + OldCherryPickKeyWarning string + CommandDoesNotSupportOpeningInEditor string + Actions Actions + Bisect Bisect + Log Log + BreakingChangesTitle string + BreakingChangesMessage string + BreakingChangesByVersion map[string]string } type Bisect struct { @@ -1554,219 +1559,224 @@ func EnglishTranslationSet() *TranslationSet { ViewDiffingOptions: "View diffing options", ViewDiffingOptionsTooltip: "View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction.", // the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part - OpenCommandLogMenu: "View command log options", - OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.", - ShowingGitDiff: "Showing output for:", - CommitDiff: "Commit diff", - CopyCommitHashToClipboard: "Copy commit hash to clipboard", - CommitHash: "Commit hash", - CommitURL: "Commit URL", - CopyCommitMessageToClipboard: "Copy commit message to clipboard", - PasteCommitMessageFromClipboard: "Paste commit message from clipboard", - SurePasteCommitMessage: "Pasting will overwrite the current commit message, continue?", - CommitMessage: "Commit message", - CommitSubject: "Commit subject", - CommitAuthor: "Commit author", - CopyCommitAttributeToClipboard: "Copy commit attribute to clipboard", - CopyCommitAttributeToClipboardTooltip: "Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author).", - CopyBranchNameToClipboard: "Copy branch name to clipboard", - CopyPathToClipboard: "Copy path to clipboard", - CopySelectedTextToClipboard: "Copy selected text to clipboard", - CommitPrefixPatternError: "Error in commitPrefix pattern", - NoFilesStagedTitle: "No files staged", - NoFilesStagedPrompt: "You have not staged any files. Commit all files?", - BranchNotFoundTitle: "Branch not found", - BranchNotFoundPrompt: "Branch not found. Create a new branch named", - BranchUnknown: "Branch unknown", - DiscardChangeTitle: "Discard change", - DiscardChangePrompt: "Are you sure you want to discard this change (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipDiscardChangeWarning' to true", - CreateNewBranchFromCommit: "Create new branch off of commit", - BuildingPatch: "Building patch", - ViewCommits: "View commits", - MinGitVersionError: "Git version must be at least 2.20 (i.e. from 2018 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.", - RunningCustomCommandStatus: "Running custom command", - SubmoduleStashAndReset: "Stash uncommitted submodule changes and update", - AndResetSubmodules: "And reset submodules", - Enter: "Enter", - EnterSubmoduleTooltip: "Enter submodule. After entering the submodule, you can press `{{.escape}}` to escape back to the parent repo.", - CopySubmoduleNameToClipboard: "Copy submodule name to clipboard", - RemoveSubmodule: "Remove submodule", - RemoveSubmodulePrompt: "Are you sure you want to remove submodule '%s' and its corresponding directory? This is irreversible.", - RemoveSubmoduleTooltip: "Remove the selected submodule and its corresponding directory.", - ResettingSubmoduleStatus: "Resetting submodule", - NewSubmoduleName: "New submodule name:", - NewSubmoduleUrl: "New submodule URL:", - NewSubmodulePath: "New submodule path:", - NewSubmodule: "New submodule", - AddingSubmoduleStatus: "Adding submodule", - UpdateSubmoduleUrl: "Update URL for submodule '%s'", - UpdatingSubmoduleUrlStatus: "Updating URL", - EditSubmoduleUrl: "Update submodule URL", - InitializingSubmoduleStatus: "Initializing submodule", - InitSubmoduleTooltip: "Initialize the selected submodule to prepare for fetching. You probably want to follow this up by invoking the 'update' action to fetch the submodule.", - Update: "Update", - Initialize: "Initialize", - SubmoduleUpdateTooltip: "Update selected submodule.", - UpdatingSubmoduleStatus: "Updating submodule", - BulkInitSubmodules: "Bulk init submodules", - BulkUpdateSubmodules: "Bulk update submodules", - BulkDeinitSubmodules: "Bulk deinit submodules", - ViewBulkSubmoduleOptions: "View bulk submodule options", - BulkSubmoduleOptions: "Bulk submodule options", - RunningCommand: "Running command", - SubCommitsTitle: "Sub-commits", - SubmodulesTitle: "Submodules", - NavigationTitle: "List panel navigation", - SuggestionsCheatsheetTitle: "Suggestions", - SuggestionsTitle: "Suggestions (press %s to focus)", - SuggestionsSubtitle: "(press %s to delete, %s to edit)", - ExtrasTitle: "Command log", - PushingTagStatus: "Pushing tag", - PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", - CommitDiffCopiedToClipboard: "Commit diff copied to clipboard", - CommitURLCopiedToClipboard: "Commit URL copied to clipboard", - CommitMessageCopiedToClipboard: "Commit message copied to clipboard", - CommitSubjectCopiedToClipboard: "Commit subject copied to clipboard", - CommitAuthorCopiedToClipboard: "Commit author copied to clipboard", - PatchCopiedToClipboard: "Patch copied to clipboard", - CopiedToClipboard: "copied to clipboard", - ErrCannotEditDirectory: "Cannot edit directories: you can only edit individual files", - ErrStageDirWithInlineMergeConflicts: "Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first", - ErrRepositoryMovedOrDeleted: "Cannot find repo. It might have been moved or deleted ¯\\_(ツ)_/¯", - CommandLog: "Command log", - ErrWorktreeMovedOrRemoved: "Cannot find worktree. It might have been moved or removed ¯\\_(ツ)_/¯", - ToggleShowCommandLog: "Toggle show/hide command log", - FocusCommandLog: "Focus command log", - CommandLogHeader: "You can hide/focus this panel by pressing '%s'\n", - RandomTip: "Random tip", - SelectParentCommitForMerge: "Select parent commit for merge", - ToggleWhitespaceInDiffView: "Toggle whitespace", - ToggleWhitespaceInDiffViewTooltip: "Toggle whether or not whitespace changes are shown in the diff view.", - IgnoreWhitespaceDiffViewSubTitle: "(ignoring whitespace)", - IgnoreWhitespaceNotSupportedHere: "Ignoring whitespace is not supported in this view", - IncreaseContextInDiffView: "Increase diff context size", - IncreaseContextInDiffViewTooltip: "Increase the amount of the context shown around changes in the diff view.", - DecreaseContextInDiffView: "Decrease diff context size", - DecreaseContextInDiffViewTooltip: "Decrease the amount of the context shown around changes in the diff view.", - DiffContextSizeChanged: "Changed diff context size to %d", - CreatePullRequestOptions: "View create pull request options", - DefaultBranch: "Default branch", - SelectBranch: "Select branch", - SelectConfigFile: "Select config file", - NoConfigFileFoundErr: "No config file found", - LoadingFileSuggestions: "Loading file suggestions", - LoadingCommits: "Loading commits", - MustSpecifyOriginError: "Must specify a remote if specifying a branch", - GitOutput: "Git output:", - GitCommandFailed: "Git command failed. Check command log for details (open with %s)", - AbortTitle: "Abort %s", - AbortPrompt: "Are you sure you want to abort the current %s?", - OpenLogMenu: "View log options", - OpenLogMenuTooltip: "View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph.", - LogMenuTitle: "Commit Log Options", - ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)", - ShowGitGraph: "Show git graph", - SortOrder: "Sort order", - SortAlphabetical: "Alphabetical", - SortByDate: "Date", - SortByRecency: "Recency", - SortBasedOnReflog: "(based on reflog)", - SortCommits: "Commit sort order", - CantChangeContextSizeError: "Cannot change context while in patch building mode because we were too lazy to support it when releasing the feature. If you really want it, please let us know!", - OpenCommitInBrowser: "Open commit in browser", - ViewBisectOptions: "View bisect options", - ConfirmRevertCommit: "Are you sure you want to revert {{.selectedCommit}}?", - RewordInEditorTitle: "Reword in editor", - RewordInEditorPrompt: "Are you sure you want to reword this commit in your editor?", - HardResetAutostashPrompt: "Are you sure you want to hard reset to '%s'? An auto-stash will be performed if necessary.", - CheckoutPrompt: "Are you sure you want to checkout '%s'?", - UpstreamGone: "(upstream gone)", - NukeDescription: "If you want to make all the changes in the worktree go away, this is the way to do it. If there are dirty submodule changes this will stash those changes in the submodule(s).", - DiscardStagedChangesDescription: "This will create a new stash entry containing only staged files and then drop it, so that the working tree is left with only unstaged changes", - EmptyOutput: "", - Patch: "Patch", - CustomPatch: "Custom patch", - CommitsCopied: "commits copied", // lowercase because it's used in a sentence - CommitCopied: "commit copied", // lowercase because it's used in a sentence - ResetPatch: "Reset patch", - ResetPatchTooltip: "Clear the current patch.", - ApplyPatch: "Apply patch", - ApplyPatchTooltip: "Apply the current patch to the working tree.", - ApplyPatchInReverse: "Apply patch in reverse", - ApplyPatchInReverseTooltip: "Apply the current patch in reverse to the working tree.", - RemovePatchFromOriginalCommit: "Remove patch from original commit (%s)", - RemovePatchFromOriginalCommitTooltip: "Remove the current patch from its commit. This is achieved by starting an interactive rebase at the commit, applying the patch in reverse, and then continuing the rebase. If later commits depend on the patch, you may need to resolve conflicts.", - MovePatchOutIntoIndex: "Move patch out into index", - MovePatchOutIntoIndexTooltip: "Move the patch out of its commit and into the index. This is achieved by starting an interactive rebase at the commit, applying the patch in reverse, continuing the rebase to completion, and then applying the patch to the index. If later commits depend on the patch, you may need to resolve conflicts.", - MovePatchIntoNewCommit: "Move patch into new commit", - MovePatchIntoNewCommitTooltip: "Move the patch out of its commit and into a new commit sitting on top of the original commit. This is achieved by starting an interactive rebase at the original commit, applying the patch in reverse, then applying the patch to the index and committing it as a new commit, before continuing the rebase to completion. If later commits depend on the patch, you may need to resolve conflicts.", - MovePatchToSelectedCommit: "Move patch to selected commit (%s)", - MovePatchToSelectedCommitTooltip: "Move the patch out of its original commit and into the selected commit. This is achieved by starting an interactive rebase at the original commit, applying the patch in reverse, then continuing the rebase up to the selected commit, before applying the patch forward and amending the seleced commit. The rebase is then continued to completion. If commits between the source and destination commit depend on the patch, you may need to resolve conflicts.", - CopyPatchToClipboard: "Copy patch to clipboard", - NoMatchesFor: "No matches for '%s' %s", - ExitSearchMode: "%s: Exit search mode", - ExitTextFilterMode: "%s: Exit filter mode", - MatchesFor: "matches for '%s' (%d of %d) %s", // lowercase because it's after other text - SearchKeybindings: "%s: Next match, %s: Previous match, %s: Exit search mode", - SearchPrefix: "Search: ", - FilterPrefix: "Filter: ", - WorktreesTitle: "Worktrees", - WorktreeTitle: "Worktree", - Switch: "Switch", - SwitchToWorktree: "Switch to worktree", - SwitchToWorktreeTooltip: "Switch to the selected worktree.", - AlreadyCheckedOutByWorktree: "This branch is checked out by worktree {{.worktreeName}}. Do you want to switch to that worktree?", - BranchCheckedOutByWorktree: "Branch {{.branchName}} is checked out by worktree {{.worktreeName}}", - DetachWorktreeTooltip: "This will run `git checkout --detach` on the worktree so that it stops hogging the branch, but the worktree's working tree will be left alone.", - Switching: "Switching", - RemoveWorktree: "Remove worktree", - RemoveWorktreeTitle: "Remove worktree", - RemoveWorktreePrompt: "Are you sure you want to remove worktree '{{.worktreeName}}'?", - ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?", - RemovingWorktree: "Deleting worktree", - DetachWorktree: "Detach worktree", - DetachingWorktree: "Detaching worktree", - AddingWorktree: "Adding worktree", - CantDeleteCurrentWorktree: "You cannot remove the current worktree!", - AlreadyInWorktree: "You are already in the selected worktree", - CantDeleteMainWorktree: "You cannot remove the main worktree!", - NoWorktreesThisRepo: "No worktrees", - MissingWorktree: "(missing)", - MainWorktree: "(main)", - NewWorktree: "New worktree", - NewWorktreePath: "New worktree path", - NewWorktreeBase: "New worktree base ref", - RemoveWorktreeTooltip: "Remove the selected worktree. This will both delete the worktree's directory, as well as metadata about the worktree in the .git directory.", - BranchNameCannotBeBlank: "Branch name cannot be blank", - NewBranchName: "New branch name", - NewBranchNameLeaveBlank: "New branch name (leave blank to checkout {{.default}})", - ViewWorktreeOptions: "View worktree options", - CreateWorktreeFrom: "Create worktree from {{.ref}}", - CreateWorktreeFromDetached: "Create worktree from {{.ref}} (detached)", - LcWorktree: "worktree", - ChangingDirectoryTo: "Changing directory to {{.path}}", - Name: "Name", - Branch: "Branch", - Path: "Path", - MarkedBaseCommitStatus: "Marked a base commit for rebase", - MarkAsBaseCommit: "Mark as base commit for rebase", - MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.", - MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑", - PleaseGoToURL: "Please go to {{.url}}", - DisabledMenuItemPrefix: "Disabled: ", - NoCopiedCommits: "No copied commits", - QuickStartInteractiveRebase: "Start interactive rebase", - QuickStartInteractiveRebaseTooltip: "Start an interactive rebase for the commits on your branch. This will include all commits from the HEAD commit down to the first merge commit or main branch commit.\nIf you would instead like to start an interactive rebase from the selected commit, press `{{.editKey}}`.", - CannotQuickStartInteractiveRebase: "Cannot start interactive rebase: the HEAD commit is a merge commit or is present on the main branch, so there is no appropriate base commit to start the rebase from. You can start an interactive rebase from a specific commit by selecting the commit and pressing `{{.editKey}}`.", - RangeSelectUp: "Range select up", - RangeSelectDown: "Range select down", - RangeSelectNotSupported: "Action does not support range selection, please select a single item", - NoItemSelected: "No item selected", - SelectedItemIsNotABranch: "Selected item is not a branch", - SelectedItemDoesNotHaveFiles: "Selected item does not have files to view", - RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules", - OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: \n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'", - CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor", + OpenCommandLogMenu: "View command log options", + OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.", + ShowingGitDiff: "Showing output for:", + CommitDiff: "Commit diff", + CopyCommitHashToClipboard: "Copy commit hash to clipboard", + CommitHash: "Commit hash", + CommitURL: "Commit URL", + CopyCommitMessageToClipboard: "Copy commit message to clipboard", + PasteCommitMessageFromClipboard: "Paste commit message from clipboard", + SurePasteCommitMessage: "Pasting will overwrite the current commit message, continue?", + CommitMessage: "Commit message", + CommitSubject: "Commit subject", + CommitAuthor: "Commit author", + CopyCommitAttributeToClipboard: "Copy commit attribute to clipboard", + CopyCommitAttributeToClipboardTooltip: "Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author).", + CopyBranchNameToClipboard: "Copy branch name to clipboard", + CopyPathToClipboard: "Copy path to clipboard", + CopySelectedTextToClipboard: "Copy selected text to clipboard", + CommitPrefixPatternError: "Error in commitPrefix pattern", + NoFilesStagedTitle: "No files staged", + NoFilesStagedPrompt: "You have not staged any files. Commit all files?", + BranchNotFoundTitle: "Branch not found", + BranchNotFoundPrompt: "Branch not found. Create a new branch named", + BranchUnknown: "Branch unknown", + DiscardChangeTitle: "Discard change", + DiscardChangePrompt: "Are you sure you want to discard this change (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipDiscardChangeWarning' to true", + CreateNewBranchFromCommit: "Create new branch off of commit", + BuildingPatch: "Building patch", + ViewCommits: "View commits", + MinGitVersionError: "Git version must be at least 2.20 (i.e. from 2018 onwards). Please upgrade your git version. Alternatively raise an issue at https://github.com/jesseduffield/lazygit/issues for lazygit to be more backwards compatible.", + RunningCustomCommandStatus: "Running custom command", + SubmoduleStashAndReset: "Stash uncommitted submodule changes and update", + AndResetSubmodules: "And reset submodules", + Enter: "Enter", + EnterSubmoduleTooltip: "Enter submodule. After entering the submodule, you can press `{{.escape}}` to escape back to the parent repo.", + CopySubmoduleNameToClipboard: "Copy submodule name to clipboard", + RemoveSubmodule: "Remove submodule", + RemoveSubmodulePrompt: "Are you sure you want to remove submodule '%s' and its corresponding directory? This is irreversible.", + RemoveSubmoduleTooltip: "Remove the selected submodule and its corresponding directory.", + ResettingSubmoduleStatus: "Resetting submodule", + NewSubmoduleName: "New submodule name:", + NewSubmoduleUrl: "New submodule URL:", + NewSubmodulePath: "New submodule path:", + NewSubmodule: "New submodule", + AddingSubmoduleStatus: "Adding submodule", + UpdateSubmoduleUrl: "Update URL for submodule '%s'", + UpdatingSubmoduleUrlStatus: "Updating URL", + EditSubmoduleUrl: "Update submodule URL", + InitializingSubmoduleStatus: "Initializing submodule", + InitSubmoduleTooltip: "Initialize the selected submodule to prepare for fetching. You probably want to follow this up by invoking the 'update' action to fetch the submodule.", + Update: "Update", + Initialize: "Initialize", + SubmoduleUpdateTooltip: "Update selected submodule.", + UpdatingSubmoduleStatus: "Updating submodule", + BulkInitSubmodules: "Bulk init submodules", + BulkUpdateSubmodules: "Bulk update submodules", + BulkDeinitSubmodules: "Bulk deinit submodules", + ViewBulkSubmoduleOptions: "View bulk submodule options", + BulkSubmoduleOptions: "Bulk submodule options", + RunningCommand: "Running command", + SubCommitsTitle: "Sub-commits", + SubmodulesTitle: "Submodules", + NavigationTitle: "List panel navigation", + SuggestionsCheatsheetTitle: "Suggestions", + SuggestionsTitle: "Suggestions (press %s to focus)", + SuggestionsSubtitle: "(press %s to delete, %s to edit)", + ExtrasTitle: "Command log", + PushingTagStatus: "Pushing tag", + PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", + CommitDiffCopiedToClipboard: "Commit diff copied to clipboard", + CommitURLCopiedToClipboard: "Commit URL copied to clipboard", + CommitMessageCopiedToClipboard: "Commit message copied to clipboard", + CommitSubjectCopiedToClipboard: "Commit subject copied to clipboard", + CommitAuthorCopiedToClipboard: "Commit author copied to clipboard", + PatchCopiedToClipboard: "Patch copied to clipboard", + CopiedToClipboard: "copied to clipboard", + ErrCannotEditDirectory: "Cannot edit directories: you can only edit individual files", + ErrStageDirWithInlineMergeConflicts: "Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first", + ErrRepositoryMovedOrDeleted: "Cannot find repo. It might have been moved or deleted ¯\\_(ツ)_/¯", + CommandLog: "Command log", + ErrWorktreeMovedOrRemoved: "Cannot find worktree. It might have been moved or removed ¯\\_(ツ)_/¯", + ToggleShowCommandLog: "Toggle show/hide command log", + FocusCommandLog: "Focus command log", + CommandLogHeader: "You can hide/focus this panel by pressing '%s'\n", + RandomTip: "Random tip", + SelectParentCommitForMerge: "Select parent commit for merge", + ToggleWhitespaceInDiffView: "Toggle whitespace", + ToggleWhitespaceInDiffViewTooltip: "Toggle whether or not whitespace changes are shown in the diff view.", + IgnoreWhitespaceDiffViewSubTitle: "(ignoring whitespace)", + IgnoreWhitespaceNotSupportedHere: "Ignoring whitespace is not supported in this view", + IncreaseContextInDiffView: "Increase diff context size", + IncreaseContextInDiffViewTooltip: "Increase the amount of the context shown around changes in the diff view.", + DecreaseContextInDiffView: "Decrease diff context size", + DecreaseContextInDiffViewTooltip: "Decrease the amount of the context shown around changes in the diff view.", + DiffContextSizeChanged: "Changed diff context size to %d", + IncreaseRenameSimilarityThresholdTooltip: "Increase the similarity threshold for a deletion and addition pair to be treated as a rename.", + IncreaseRenameSimilarityThreshold: "Increase rename similarity threshold", + DecreaseRenameSimilarityThresholdTooltip: "Decrease the similarity threshold for a deletion and addition pair to be treated as a rename.", + DecreaseRenameSimilarityThreshold: "Decrease rename similarity threshold", + RenameSimilarityThresholdChanged: "Changed rename similarity threshold to %d%%", + CreatePullRequestOptions: "View create pull request options", + DefaultBranch: "Default branch", + SelectBranch: "Select branch", + SelectConfigFile: "Select config file", + NoConfigFileFoundErr: "No config file found", + LoadingFileSuggestions: "Loading file suggestions", + LoadingCommits: "Loading commits", + MustSpecifyOriginError: "Must specify a remote if specifying a branch", + GitOutput: "Git output:", + GitCommandFailed: "Git command failed. Check command log for details (open with %s)", + AbortTitle: "Abort %s", + AbortPrompt: "Are you sure you want to abort the current %s?", + OpenLogMenu: "View log options", + OpenLogMenuTooltip: "View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph.", + LogMenuTitle: "Commit Log Options", + ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)", + ShowGitGraph: "Show git graph", + SortOrder: "Sort order", + SortAlphabetical: "Alphabetical", + SortByDate: "Date", + SortByRecency: "Recency", + SortBasedOnReflog: "(based on reflog)", + SortCommits: "Commit sort order", + CantChangeContextSizeError: "Cannot change context while in patch building mode because we were too lazy to support it when releasing the feature. If you really want it, please let us know!", + OpenCommitInBrowser: "Open commit in browser", + ViewBisectOptions: "View bisect options", + ConfirmRevertCommit: "Are you sure you want to revert {{.selectedCommit}}?", + RewordInEditorTitle: "Reword in editor", + RewordInEditorPrompt: "Are you sure you want to reword this commit in your editor?", + HardResetAutostashPrompt: "Are you sure you want to hard reset to '%s'? An auto-stash will be performed if necessary.", + CheckoutPrompt: "Are you sure you want to checkout '%s'?", + UpstreamGone: "(upstream gone)", + NukeDescription: "If you want to make all the changes in the worktree go away, this is the way to do it. If there are dirty submodule changes this will stash those changes in the submodule(s).", + DiscardStagedChangesDescription: "This will create a new stash entry containing only staged files and then drop it, so that the working tree is left with only unstaged changes", + EmptyOutput: "", + Patch: "Patch", + CustomPatch: "Custom patch", + CommitsCopied: "commits copied", // lowercase because it's used in a sentence + CommitCopied: "commit copied", // lowercase because it's used in a sentence + ResetPatch: "Reset patch", + ResetPatchTooltip: "Clear the current patch.", + ApplyPatch: "Apply patch", + ApplyPatchTooltip: "Apply the current patch to the working tree.", + ApplyPatchInReverse: "Apply patch in reverse", + ApplyPatchInReverseTooltip: "Apply the current patch in reverse to the working tree.", + RemovePatchFromOriginalCommit: "Remove patch from original commit (%s)", + RemovePatchFromOriginalCommitTooltip: "Remove the current patch from its commit. This is achieved by starting an interactive rebase at the commit, applying the patch in reverse, and then continuing the rebase. If later commits depend on the patch, you may need to resolve conflicts.", + MovePatchOutIntoIndex: "Move patch out into index", + MovePatchOutIntoIndexTooltip: "Move the patch out of its commit and into the index. This is achieved by starting an interactive rebase at the commit, applying the patch in reverse, continuing the rebase to completion, and then applying the patch to the index. If later commits depend on the patch, you may need to resolve conflicts.", + MovePatchIntoNewCommit: "Move patch into new commit", + MovePatchIntoNewCommitTooltip: "Move the patch out of its commit and into a new commit sitting on top of the original commit. This is achieved by starting an interactive rebase at the original commit, applying the patch in reverse, then applying the patch to the index and committing it as a new commit, before continuing the rebase to completion. If later commits depend on the patch, you may need to resolve conflicts.", + MovePatchToSelectedCommit: "Move patch to selected commit (%s)", + MovePatchToSelectedCommitTooltip: "Move the patch out of its original commit and into the selected commit. This is achieved by starting an interactive rebase at the original commit, applying the patch in reverse, then continuing the rebase up to the selected commit, before applying the patch forward and amending the seleced commit. The rebase is then continued to completion. If commits between the source and destination commit depend on the patch, you may need to resolve conflicts.", + CopyPatchToClipboard: "Copy patch to clipboard", + NoMatchesFor: "No matches for '%s' %s", + ExitSearchMode: "%s: Exit search mode", + ExitTextFilterMode: "%s: Exit filter mode", + MatchesFor: "matches for '%s' (%d of %d) %s", // lowercase because it's after other text + SearchKeybindings: "%s: Next match, %s: Previous match, %s: Exit search mode", + SearchPrefix: "Search: ", + FilterPrefix: "Filter: ", + WorktreesTitle: "Worktrees", + WorktreeTitle: "Worktree", + Switch: "Switch", + SwitchToWorktree: "Switch to worktree", + SwitchToWorktreeTooltip: "Switch to the selected worktree.", + AlreadyCheckedOutByWorktree: "This branch is checked out by worktree {{.worktreeName}}. Do you want to switch to that worktree?", + BranchCheckedOutByWorktree: "Branch {{.branchName}} is checked out by worktree {{.worktreeName}}", + DetachWorktreeTooltip: "This will run `git checkout --detach` on the worktree so that it stops hogging the branch, but the worktree's working tree will be left alone.", + Switching: "Switching", + RemoveWorktree: "Remove worktree", + RemoveWorktreeTitle: "Remove worktree", + RemoveWorktreePrompt: "Are you sure you want to remove worktree '{{.worktreeName}}'?", + ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?", + RemovingWorktree: "Deleting worktree", + DetachWorktree: "Detach worktree", + DetachingWorktree: "Detaching worktree", + AddingWorktree: "Adding worktree", + CantDeleteCurrentWorktree: "You cannot remove the current worktree!", + AlreadyInWorktree: "You are already in the selected worktree", + CantDeleteMainWorktree: "You cannot remove the main worktree!", + NoWorktreesThisRepo: "No worktrees", + MissingWorktree: "(missing)", + MainWorktree: "(main)", + NewWorktree: "New worktree", + NewWorktreePath: "New worktree path", + NewWorktreeBase: "New worktree base ref", + RemoveWorktreeTooltip: "Remove the selected worktree. This will both delete the worktree's directory, as well as metadata about the worktree in the .git directory.", + BranchNameCannotBeBlank: "Branch name cannot be blank", + NewBranchName: "New branch name", + NewBranchNameLeaveBlank: "New branch name (leave blank to checkout {{.default}})", + ViewWorktreeOptions: "View worktree options", + CreateWorktreeFrom: "Create worktree from {{.ref}}", + CreateWorktreeFromDetached: "Create worktree from {{.ref}} (detached)", + LcWorktree: "worktree", + ChangingDirectoryTo: "Changing directory to {{.path}}", + Name: "Name", + Branch: "Branch", + Path: "Path", + MarkedBaseCommitStatus: "Marked a base commit for rebase", + MarkAsBaseCommit: "Mark as base commit for rebase", + MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.", + MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑", + PleaseGoToURL: "Please go to {{.url}}", + DisabledMenuItemPrefix: "Disabled: ", + NoCopiedCommits: "No copied commits", + QuickStartInteractiveRebase: "Start interactive rebase", + QuickStartInteractiveRebaseTooltip: "Start an interactive rebase for the commits on your branch. This will include all commits from the HEAD commit down to the first merge commit or main branch commit.\nIf you would instead like to start an interactive rebase from the selected commit, press `{{.editKey}}`.", + CannotQuickStartInteractiveRebase: "Cannot start interactive rebase: the HEAD commit is a merge commit or is present on the main branch, so there is no appropriate base commit to start the rebase from. You can start an interactive rebase from a specific commit by selecting the commit and pressing `{{.editKey}}`.", + RangeSelectUp: "Range select up", + RangeSelectDown: "Range select down", + RangeSelectNotSupported: "Action does not support range selection, please select a single item", + NoItemSelected: "No item selected", + SelectedItemIsNotABranch: "Selected item is not a branch", + SelectedItemDoesNotHaveFiles: "Selected item does not have files to view", + RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules", + OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: \n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'", + CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor", Actions: Actions{ // TODO: combine this with the original keybinding descriptions (those are all in lowercase atm) diff --git a/pkg/integration/tests/diff/rename_similarity_threshold_change.go b/pkg/integration/tests/diff/rename_similarity_threshold_change.go new file mode 100644 index 00000000000..170838fd321 --- /dev/null +++ b/pkg/integration/tests/diff/rename_similarity_threshold_change.go @@ -0,0 +1,41 @@ +package diff + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RenameSimilarityThresholdChange = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Change the rename similarity threshold while in the commits panel", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("original", "one\ntwo\nthree\nfour\nfive\n") + shell.Commit("add original") + + shell.DeleteFileAndAdd("original") + shell.CreateFileAndAdd("renamed", "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\n") + shell.Commit("change name and contents") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits().Focus() + + t.Views().Main(). + ContainsLines( + Contains("2 files changed, 10 insertions(+), 5 deletions(-)"), + ) + + t.Views().Commits(). + Press(keys.Universal.DecreaseRenameSimilarityThreshold). + Tap(func() { + t.ExpectToast(Equals("Changed rename similarity threshold to 45%")) + }) + + t.Views().Main(). + ContainsLines( + Contains("original => renamed"), + Contains("1 file changed, 5 insertions(+)"), + ) + }, +}) diff --git a/pkg/integration/tests/file/rename_similarity_threshold_change.go b/pkg/integration/tests/file/rename_similarity_threshold_change.go new file mode 100644 index 00000000000..ec3aad24117 --- /dev/null +++ b/pkg/integration/tests/file/rename_similarity_threshold_change.go @@ -0,0 +1,35 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RenameSimilarityThresholdChange = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Change the rename similarity threshold while in the files panel", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("original", "one\ntwo\nthree\nfour\nfive\n") + shell.Commit("add original") + + shell.DeleteFileAndAdd("original") + shell.CreateFileAndAdd("renamed", "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\n") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Contains("D ").Contains("original"), + Contains("A ").Contains("renamed"), + ). + Press(keys.Universal.DecreaseRenameSimilarityThreshold). + Tap(func() { + t.ExpectToast(Equals("Changed rename similarity threshold to 45%")) + }). + Lines( + Contains("R ").Contains("original → renamed"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index fcc0b74bbbf..477fdee44cd 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -149,6 +149,7 @@ var tests = []*components.IntegrationTest{ diff.DiffAndApplyPatch, diff.DiffCommits, diff.IgnoreWhitespace, + diff.RenameSimilarityThresholdChange, file.CopyMenu, file.DirWithUntrackedFile, file.DiscardAllDirChanges, @@ -161,6 +162,7 @@ var tests = []*components.IntegrationTest{ file.DiscardVariousChangesRangeSelect, file.Gitignore, file.RememberCommitMessageAfterFail, + file.RenameSimilarityThresholdChange, file.StageChildrenRangeSelect, file.StageRangeSelect, filter_and_search.FilterCommitFiles, diff --git a/schema/config.json b/schema/config.json index 23e052f69b7..eb93600a33b 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1322,6 +1322,14 @@ "type": "string", "default": "{" }, + "increaseRenameSimilarityThreshold": { + "type": "string", + "default": ")" + }, + "decreaseRenameSimilarityThreshold": { + "type": "string", + "default": "(" + }, "openDiffTool": { "type": "string", "default": "\u003cc-t\u003e" From f2db9fa3f91311fb42967234222bc510cf89b8bf Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 13 Jul 2024 14:54:09 +1000 Subject: [PATCH 2/2] Revert "Check for fixup commits on CI" This reverts commit 7652d579f587c3202d1d80464557cfaa8005b3de. Not working on forks, and I don't have time to fix right now --- .github/workflows/ci.yml | 22 ---------------------- scripts/check_for_fixups.sh | 25 ------------------------- 2 files changed, 47 deletions(-) delete mode 100755 scripts/check_for_fixups.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b0a04938d5..64c890894c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -219,25 +219,3 @@ jobs: CODACY_PROJECT_TOKEN=${{ secrets.CODACY_PROJECT_TOKEN }} \ bash <(curl -Ls https://coverage.codacy.com/get.sh) report \ --force-coverage-parser go -r coverage.out - - check-for-fixups: - runs-on: ubuntu-latest - if: github.ref != 'refs/heads/master' - steps: - # See https://github.com/actions/checkout/issues/552#issuecomment-1167086216 - - name: "PR commits + 1" - run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" - - - name: "Checkout PR branch and all PR commits" - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - fetch-depth: ${{ env.PR_FETCH_DEPTH }} - - - name: "Fetch the other branch with enough history for a common merge-base commit" - run: | - git fetch origin ${{ github.event.pull_request.base.ref }} - - - name: Check for fixups - run: | - ./scripts/check_for_fixups.sh ${{ github.event.pull_request.base.ref }} diff --git a/scripts/check_for_fixups.sh b/scripts/check_for_fixups.sh deleted file mode 100755 index c2c2e1a21ba..00000000000 --- a/scripts/check_for_fixups.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -base_ref=$1 - -# Determine the base commit -base_commit=$(git merge-base HEAD origin/"$base_ref") - -# Check if base_commit is set correctly -if [ -z "$base_commit" ]; then - echo "Failed to determine base commit." - exit 1 -fi -echo "Base commit: $base_commit" - -# Get commits with "fixup!" in the message from base_commit to HEAD -commits=$(git log -i -P --grep "fixup\!" --format="%h %s" "$base_commit..HEAD") - -if [ -z "$commits" ]; then - echo "No fixup commits found." - exit 0 -else - echo "Fixup commits found:" - echo "$commits" - exit 1 -fi