1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

Support setting the similarity threshold for detecting renames

This commit is contained in:
István Donkó
2023-09-25 17:32:12 +02:00
committed by Jesse Duffield
parent bfe2dd4ed8
commit b9107d5fc8
26 changed files with 909 additions and 618 deletions

View File

@ -521,6 +521,8 @@ keybinding:
toggleWhitespaceInDiffView: <c-w> toggleWhitespaceInDiffView: <c-w>
increaseContextInDiffView: '}' increaseContextInDiffView: '}'
decreaseContextInDiffView: '{' decreaseContextInDiffView: '{'
increaseRenameSimilarityThreshold: )
decreaseRenameSimilarityThreshold: (
openDiffTool: <c-t> openDiffTool: <c-t>
status: status:
checkForUpdate: u checkForUpdate: u

View File

@ -14,6 +14,8 @@ _Legend: `<c-b>` means ctrl+b, `<a-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. | | `` @ `` | 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 `` | 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. | | `` 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. | | `` } `` | 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. | | `` { `` | 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. | | `` : `` | 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. |

View File

@ -14,6 +14,8 @@ _Legend: `<c-b>` means ctrl+b, `<a-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. | | `` @ `` | コマンドログメニューを開く | 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 `` | 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. | | `` 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. | | `` } `` | 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. | | `` { `` | 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. | | `` : `` | カスタムコマンドを実行 | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. |

View File

@ -14,6 +14,8 @@ _Legend: `<c-b>` means ctrl+b, `<a-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. | | `` @ `` | 명령어 로그 메뉴 열기 | 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 `` | 푸시 | 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. | | `` 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 보기의 변경 사항 주위에 표시되는 컨텍스트의 크기를 늘리기 | 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. | | `` { `` | 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. | | `` : `` | 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. |

View File

@ -14,6 +14,8 @@ _Legend: `<c-b>` means ctrl+b, `<a-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. | | `` @ `` | 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 `` | 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. | | `` 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. | | `` } `` | 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. | | `` { `` | 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. | | `` : `` | 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. |

View File

@ -14,6 +14,8 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-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ń. | | `` @ `` | 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 `` | 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. | | `` 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. | | `` } `` | 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. | | `` { `` | 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. | | `` : `` | 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. |

View File

@ -14,6 +14,8 @@ _Связки клавиш_
| `` @ `` | Открыть меню журнала команд | View options for the command log e.g. show/hide the command log and focus the command log. | | `` @ `` | Открыть меню журнала команд | 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 `` | Отправить изменения | 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. | | `` 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. | | `` } `` | Увеличить размер контекста, отображаемого вокруг изменений в просмотрщике сравнении | 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. | | `` { `` | Уменьшите размер контекста, отображаемого вокруг изменений в просмотрщике сравнении | 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. | | `` : `` | Выполнить пользовательскую команду | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. |

View File

@ -14,6 +14,8 @@ _Legend: `<c-b>` means ctrl+b, `<a-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. | | `` @ `` | 打开命令日志菜单 | 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 `` | 推送 | 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. | | `` 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. | | `` } `` | 扩大差异视图中显示的上下文范围 | 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. | | `` { `` | 缩小差异视图中显示的上下文范围 | 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. | | `` : `` | 执行自定义命令 | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. |

View File

@ -14,6 +14,8 @@ _說明`<c-b>` 表示 CtrlB、`<a-b>` 表示 AltB`B`表示 ShiftB
| `` @ `` | 開啟命令記錄選單 | View options for the command log e.g. show/hide the command log and focus the command log. | | `` @ `` | 開啟命令記錄選單 | 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 `` | 推送 | 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. | | `` 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. | | `` } `` | 增加差異檢視中顯示變更周圍上下文的大小 | 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. | | `` { `` | 減小差異檢視中顯示變更周圍上下文的大小 | 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. | | `` : `` | 執行自訂命令 | Bring up a prompt where you can enter a shell command to execute. Not to be confused with pre-configured custom commands. |

View File

@ -271,6 +271,7 @@ func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) oscommand
Arg("-p"). Arg("-p").
Arg(hash). Arg(hash).
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
ArgIf(filterPath != "", "--", filterPath). ArgIf(filterPath != "", "--", filterPath).
Dir(self.repoPaths.worktreePath). Dir(self.repoPaths.worktreePath).
ToArgv() ToArgv()

View File

@ -231,6 +231,7 @@ func TestCommitShowCmdObj(t *testing.T) {
testName string testName string
filterPath string filterPath string
contextSize int contextSize int
similarityThreshold int
ignoreWhitespace bool ignoreWhitespace bool
extDiffCmd string extDiffCmd string
expected []string expected []string
@ -241,41 +242,55 @@ func TestCommitShowCmdObj(t *testing.T) {
testName: "Default case without filter path", testName: "Default case without filter path",
filterPath: "", filterPath: "",
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
ignoreWhitespace: false, ignoreWhitespace: false,
extDiffCmd: "", extDiffCmd: "",
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890"}, 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", testName: "Default case with filter path",
filterPath: "file.txt", filterPath: "file.txt",
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
ignoreWhitespace: false, ignoreWhitespace: false,
extDiffCmd: "", 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"}, 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", testName: "Show diff with custom context size",
filterPath: "", filterPath: "",
contextSize: 77, contextSize: 77,
similarityThreshold: 50,
ignoreWhitespace: false, ignoreWhitespace: false,
extDiffCmd: "", extDiffCmd: "",
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890"}, 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 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, ignoring whitespace", testName: "Show diff, ignoring whitespace",
filterPath: "", filterPath: "",
contextSize: 77, contextSize: 77,
similarityThreshold: 50,
ignoreWhitespace: true, ignoreWhitespace: true,
extDiffCmd: "", 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"}, 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", testName: "Show diff with external diff command",
filterPath: "", filterPath: "",
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
ignoreWhitespace: false, ignoreWhitespace: false,
extDiffCmd: "difft --color=always", 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"}, 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 := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
appState.RenameSimilarityThreshold = s.similarityThreshold
runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil) runner := oscommands.NewFakeRunner(t).ExpectGitArgs(s.expected, "", nil)
repoPaths := RepoPaths{ repoPaths := RepoPaths{

View File

@ -100,15 +100,19 @@ type FileStatus struct {
PreviousName string PreviousName string
} }
func (c *FileLoader) gitStatus(opts GitStatusOptions) ([]FileStatus, error) { func (self *FileLoader) gitStatus(opts GitStatusOptions) ([]FileStatus, error) {
cmdArgs := NewGitCmd("status"). cmdArgs := NewGitCmd("status").
Arg(opts.UntrackedFilesArg). Arg(opts.UntrackedFilesArg).
Arg("--porcelain"). Arg("--porcelain").
Arg("-z"). Arg("-z").
ArgIf(opts.NoRenames, "--no-renames"). ArgIfElse(
opts.NoRenames,
"--no-renames",
fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold),
).
ToArgv() ToArgv()
statusLines, _, err := c.cmd.New(cmdArgs).DontLog().RunWithOutputs() statusLines, _, err := self.cmd.New(cmdArgs).DontLog().RunWithOutputs()
if err != nil { if err != nil {
return []FileStatus{}, err return []FileStatus{}, err
} }

View File

@ -5,12 +5,14 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestFileGetStatusFiles(t *testing.T) { func TestFileGetStatusFiles(t *testing.T) {
type scenario struct { type scenario struct {
testName string testName string
similarityThreshold int
runner oscommands.ICmdObjRunner runner oscommands.ICmdObjRunner
expectedFiles []*models.File expectedFiles []*models.File
} }
@ -18,14 +20,16 @@ func TestFileGetStatusFiles(t *testing.T) {
scenarios := []scenario{ scenarios := []scenario{
{ {
"No files found", "No files found",
50,
oscommands.NewFakeRunner(t). 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{}, []*models.File{},
}, },
{ {
"Several files found", "Several files found",
50,
oscommands.NewFakeRunner(t). 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", "MM file1.txt\x00A file3.txt\x00AM file2.txt\x00?? file4.txt\x00UU file5.txt",
nil, nil,
), ),
@ -94,8 +98,9 @@ func TestFileGetStatusFiles(t *testing.T) {
}, },
{ {
"File with new line char", "File with new line char",
50,
oscommands.NewFakeRunner(t). 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{ []*models.File{
{ {
Name: "a\nb.txt", Name: "a\nb.txt",
@ -113,8 +118,9 @@ func TestFileGetStatusFiles(t *testing.T) {
}, },
{ {
"Renamed files", "Renamed files",
50,
oscommands.NewFakeRunner(t). 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", "R after1.txt\x00before1.txt\x00RM after2.txt\x00before2.txt",
nil, nil,
), ),
@ -149,8 +155,9 @@ func TestFileGetStatusFiles(t *testing.T) {
}, },
{ {
"File with arrow in name", "File with arrow in name",
50,
oscommands.NewFakeRunner(t). 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`, `?? a -> b.txt`,
nil, nil,
), ),
@ -175,8 +182,11 @@ func TestFileGetStatusFiles(t *testing.T) {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
cmd := oscommands.NewDummyCmdObjBuilder(s.runner) cmd := oscommands.NewDummyCmdObjBuilder(s.runner)
appState := &config.AppState{}
appState.RenameSimilarityThreshold = s.similarityThreshold
loader := &FileLoader{ loader := &FileLoader{
GitCommon: buildGitCommon(commonDeps{}), GitCommon: buildGitCommon(commonDeps{appState: appState}),
cmd: cmd, cmd: cmd,
config: &FakeFileLoaderConfig{showUntrackedFiles: "yes"}, config: &FakeFileLoaderConfig{showUntrackedFiles: "yes"},
getFileType: func(string) string { return "file" }, getFileType: func(string) string { return "file" },

View File

@ -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("--color=%s", self.UserConfig.Git.Paging.ColorArg)).
Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)). Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
Arg(fmt.Sprintf("stash@{%d}", index)). Arg(fmt.Sprintf("stash@{%d}", index)).
Dir(self.repoPaths.worktreePath). Dir(self.repoPaths.worktreePath).
ToArgv() ToArgv()

View File

@ -101,6 +101,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
testName string testName string
index int index int
contextSize int contextSize int
similarityThreshold int
ignoreWhitespace bool ignoreWhitespace bool
expected []string expected []string
} }
@ -110,22 +111,33 @@ func TestStashStashEntryCmdObj(t *testing.T) {
testName: "Default case", testName: "Default case",
index: 5, index: 5,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
ignoreWhitespace: false, ignoreWhitespace: false,
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "stash@{5}"}, 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", testName: "Show diff with custom context size",
index: 5, index: 5,
contextSize: 77, contextSize: 77,
similarityThreshold: 50,
ignoreWhitespace: false, ignoreWhitespace: false,
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=77", "stash@{5}"}, expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=77", "--find-renames=50%", "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", testName: "Default case",
index: 5, index: 5,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
ignoreWhitespace: true, ignoreWhitespace: true,
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--ignore-all-space", "stash@{5}"}, 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 := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
appState.RenameSimilarityThreshold = s.similarityThreshold
repoPaths := RepoPaths{ repoPaths := RepoPaths{
worktreePath: "/path/to/worktree", worktreePath: "/path/to/worktree",
} }

View File

@ -263,6 +263,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain
Arg(fmt.Sprintf("--unified=%d", contextSize)). Arg(fmt.Sprintf("--unified=%d", contextSize)).
Arg(fmt.Sprintf("--color=%s", colorArg)). Arg(fmt.Sprintf("--color=%s", colorArg)).
ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space"). ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
Arg(fmt.Sprintf("--find-renames=%d%%", self.AppState.RenameSimilarityThreshold)).
ArgIf(cached, "--cached"). ArgIf(cached, "--cached").
ArgIf(noIndex, "--no-index"). ArgIf(noIndex, "--no-index").
Arg("--"). Arg("--").

View File

@ -211,6 +211,7 @@ func TestWorkingTreeDiff(t *testing.T) {
cached bool cached bool
ignoreWhitespace bool ignoreWhitespace bool
contextSize int contextSize int
similarityThreshold int
runner *oscommands.FakeCmdObjRunner runner *oscommands.FakeCmdObjRunner
} }
@ -228,8 +229,9 @@ func TestWorkingTreeDiff(t *testing.T) {
cached: false, cached: false,
ignoreWhitespace: false, ignoreWhitespace: false,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
runner: oscommands.NewFakeRunner(t). 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", testName: "cached",
@ -242,8 +244,9 @@ func TestWorkingTreeDiff(t *testing.T) {
cached: true, cached: true,
ignoreWhitespace: false, ignoreWhitespace: false,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
runner: oscommands.NewFakeRunner(t). 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", testName: "plain",
@ -256,8 +259,9 @@ func TestWorkingTreeDiff(t *testing.T) {
cached: false, cached: false,
ignoreWhitespace: false, ignoreWhitespace: false,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
runner: oscommands.NewFakeRunner(t). 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", testName: "File not tracked and file has no staged changes",
@ -270,8 +274,9 @@ func TestWorkingTreeDiff(t *testing.T) {
cached: false, cached: false,
ignoreWhitespace: false, ignoreWhitespace: false,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
runner: oscommands.NewFakeRunner(t). 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)", testName: "Default case (ignore whitespace)",
@ -284,8 +289,9 @@ func TestWorkingTreeDiff(t *testing.T) {
cached: false, cached: false,
ignoreWhitespace: true, ignoreWhitespace: true,
contextSize: 3, contextSize: 3,
similarityThreshold: 50,
runner: oscommands.NewFakeRunner(t). 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", testName: "Show diff with custom context size",
@ -298,8 +304,24 @@ func TestWorkingTreeDiff(t *testing.T) {
cached: false, cached: false,
ignoreWhitespace: false, ignoreWhitespace: false,
contextSize: 17, contextSize: 17,
similarityThreshold: 50,
runner: oscommands.NewFakeRunner(t). 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=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=3", "--color=always", "--find-renames=33%", "--", "test.txt"}, expectedResult, nil),
}, },
} }
@ -309,6 +331,7 @@ func TestWorkingTreeDiff(t *testing.T) {
appState := &config.AppState{} appState := &config.AppState{}
appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace appState.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
appState.DiffContextSize = s.contextSize appState.DiffContextSize = s.contextSize
appState.RenameSimilarityThreshold = s.similarityThreshold
repoPaths := RepoPaths{ repoPaths := RepoPaths{
worktreePath: "/path/to/worktree", worktreePath: "/path/to/worktree",
} }

View File

@ -370,6 +370,7 @@ type AppState struct {
HideCommandLog bool HideCommandLog bool
IgnoreWhitespaceInDiffView bool IgnoreWhitespaceInDiffView bool
DiffContextSize int DiffContextSize int
RenameSimilarityThreshold int
LocalBranchSortOrder string LocalBranchSortOrder string
RemoteBranchSortOrder string RemoteBranchSortOrder string
@ -390,6 +391,7 @@ func getDefaultAppState() *AppState {
StartupPopupVersion: 0, StartupPopupVersion: 0,
LastVersion: "", LastVersion: "",
DiffContextSize: 3, DiffContextSize: 3,
RenameSimilarityThreshold: 50,
LocalBranchSortOrder: "recency", LocalBranchSortOrder: "recency",
RemoteBranchSortOrder: "alphabetical", RemoteBranchSortOrder: "alphabetical",
GitLogOrder: "", // should be "topo-order" eventually GitLogOrder: "", // should be "topo-order" eventually

View File

@ -407,6 +407,8 @@ type KeybindingUniversalConfig struct {
ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"` ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"`
IncreaseContextInDiffView string `yaml:"increaseContextInDiffView"` IncreaseContextInDiffView string `yaml:"increaseContextInDiffView"`
DecreaseContextInDiffView string `yaml:"decreaseContextInDiffView"` DecreaseContextInDiffView string `yaml:"decreaseContextInDiffView"`
IncreaseRenameSimilarityThreshold string `yaml:"increaseRenameSimilarityThreshold"`
DecreaseRenameSimilarityThreshold string `yaml:"decreaseRenameSimilarityThreshold"`
OpenDiffTool string `yaml:"openDiffTool"` OpenDiffTool string `yaml:"openDiffTool"`
} }
@ -843,6 +845,8 @@ func GetDefaultConfig() *UserConfig {
ToggleWhitespaceInDiffView: "<c-w>", ToggleWhitespaceInDiffView: "<c-w>",
IncreaseContextInDiffView: "}", IncreaseContextInDiffView: "}",
DecreaseContextInDiffView: "{", DecreaseContextInDiffView: "{",
IncreaseRenameSimilarityThreshold: ")",
DecreaseRenameSimilarityThreshold: "(",
OpenDiffTool: "<c-t>", OpenDiffTool: "<c-t>",
}, },
Status: KeybindingStatusConfig{ Status: KeybindingStatusConfig{

View File

@ -179,6 +179,7 @@ func (gui *Gui) resetHelpersAndControllers() {
undoController := controllers.NewUndoController(common) undoController := controllers.NewUndoController(common)
globalController := controllers.NewGlobalController(common) globalController := controllers.NewGlobalController(common)
contextLinesController := controllers.NewContextLinesController(common) contextLinesController := controllers.NewContextLinesController(common)
renameSimilarityThresholdController := controllers.NewRenameSimilarityThresholdController(common)
verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common, &gui.viewBufferManagerMap) verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common, &gui.viewBufferManagerMap)
branchesController := controllers.NewBranchesController(common) branchesController := controllers.NewBranchesController(common)
@ -383,6 +384,7 @@ func (gui *Gui) resetHelpersAndControllers() {
undoController, undoController,
globalController, globalController,
contextLinesController, contextLinesController,
renameSimilarityThresholdController,
jumpToSideWindowController, jumpToSideWindowController,
syncController, syncController,
) )

View File

@ -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(),
)
}

View File

@ -673,6 +673,11 @@ type TranslationSet struct {
DecreaseContextInDiffView string DecreaseContextInDiffView string
DecreaseContextInDiffViewTooltip string DecreaseContextInDiffViewTooltip string
DiffContextSizeChanged string DiffContextSizeChanged string
IncreaseRenameSimilarityThreshold string
IncreaseRenameSimilarityThresholdTooltip string
DecreaseRenameSimilarityThreshold string
DecreaseRenameSimilarityThresholdTooltip string
RenameSimilarityThresholdChanged string
CreatePullRequestOptions string CreatePullRequestOptions string
DefaultBranch string DefaultBranch string
SelectBranch string SelectBranch string
@ -1649,6 +1654,11 @@ func EnglishTranslationSet() *TranslationSet {
DecreaseContextInDiffView: "Decrease diff context size", DecreaseContextInDiffView: "Decrease diff context size",
DecreaseContextInDiffViewTooltip: "Decrease the amount of the context shown around changes in the diff view.", DecreaseContextInDiffViewTooltip: "Decrease the amount of the context shown around changes in the diff view.",
DiffContextSizeChanged: "Changed diff context size to %d", 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", CreatePullRequestOptions: "View create pull request options",
DefaultBranch: "Default branch", DefaultBranch: "Default branch",
SelectBranch: "Select branch", SelectBranch: "Select branch",

View File

@ -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(+)"),
)
},
})

View File

@ -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"),
)
},
})

View File

@ -149,6 +149,7 @@ var tests = []*components.IntegrationTest{
diff.DiffAndApplyPatch, diff.DiffAndApplyPatch,
diff.DiffCommits, diff.DiffCommits,
diff.IgnoreWhitespace, diff.IgnoreWhitespace,
diff.RenameSimilarityThresholdChange,
file.CopyMenu, file.CopyMenu,
file.DirWithUntrackedFile, file.DirWithUntrackedFile,
file.DiscardAllDirChanges, file.DiscardAllDirChanges,
@ -161,6 +162,7 @@ var tests = []*components.IntegrationTest{
file.DiscardVariousChangesRangeSelect, file.DiscardVariousChangesRangeSelect,
file.Gitignore, file.Gitignore,
file.RememberCommitMessageAfterFail, file.RememberCommitMessageAfterFail,
file.RenameSimilarityThresholdChange,
file.StageChildrenRangeSelect, file.StageChildrenRangeSelect,
file.StageRangeSelect, file.StageRangeSelect,
filter_and_search.FilterCommitFiles, filter_and_search.FilterCommitFiles,

View File

@ -1322,6 +1322,14 @@
"type": "string", "type": "string",
"default": "{" "default": "{"
}, },
"increaseRenameSimilarityThreshold": {
"type": "string",
"default": ")"
},
"decreaseRenameSimilarityThreshold": {
"type": "string",
"default": "("
},
"openDiffTool": { "openDiffTool": {
"type": "string", "type": "string",
"default": "\u003cc-t\u003e" "default": "\u003cc-t\u003e"