Skip to content

Feature/ignore by file extension #4390

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ keybinding:
findBaseCommitForFixup: <c-f>
confirmDiscard: x
ignoreFile: i
ignoreFileExtension: I
refreshFiles: r
stashAllChanges: s
viewStashOptions: S
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` e `` | Edit | Open file in external editor. |
| `` o `` | Open file | Open file in default application. |
| `` i `` | Ignore or exclude file | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | Refresh files | |
| `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | View stash options | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` e `` | Edit | Open file in external editor. |
| `` o `` | ファイルを開く | Open file in default application. |
| `` i `` | ファイルをignore | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | ファイルをリフレッシュ | |
| `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | View stash options | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` e `` | Edit | Open file in external editor. |
| `` o `` | 파일 닫기 | Open file in default application. |
| `` i `` | Ignore file | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | 파일 새로고침 | |
| `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | Stash 옵션 보기 | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` e `` | Edit | Open file in external editor. |
| `` o `` | Open bestand | Open file in default application. |
| `` i `` | Ignore or exclude file | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | Refresh bestanden | |
| `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | Bekijk stash opties | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita,
| `` e `` | Edytuj | Otwórz plik w zewnętrznym edytorze. |
| `` o `` | Otwórz plik | Otwórz plik w domyślnej aplikacji. |
| `` i `` | Ignoruj lub wyklucz plik | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | Odśwież pliki | |
| `` s `` | Schowaj | Schowaj wszystkie zmiany. Dla innych wariantów schowania, użyj klawisza wyświetlania opcji schowka. |
| `` S `` | Wyświetl opcje schowka | Wyświetl opcje schowka (np. schowaj wszystko, schowaj zatwierdzone, schowaj niezatwierdzone). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Veja a documentação:
| `` e `` | Editar | Abrir arquivo no editor externo. |
| `` o `` | Abrir arquivo | Abrir arquivo no aplicativo padrão. |
| `` i `` | Ignore or exclude file | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | Atualizar arquivos | |
| `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | View stash options | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` e `` | Edit | Open file in external editor. |
| `` o `` | Открыть файл | Open file in default application. |
| `` i `` | Игнорировать или исключить файл | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | Обновить файлы | |
| `` s `` | Stash | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | Просмотреть параметры хранилища | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ _图例:`<c-b>` 意味着ctrl+b, `<a-b>意味着Alt+b, `B` 意味着shift+b_
| `` e `` | 编辑 | 使用外部编辑器打开文件 |
| `` o `` | 打开文件 | 使用默认程序打开该文件 |
| `` i `` | 忽略文件 | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | 刷新文件 | |
| `` s `` | 贮藏 | 贮藏所有变更.若要使用其他贮藏变体,请使用查看贮藏选项快捷键 |
| `` S `` | 查看贮藏选项 | 查看贮藏选项(例如:贮藏所有、贮藏已暂存变更、贮藏未暂存变更) |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` e `` | 編輯 | 使用外部編輯器開啟 |
| `` o `` | 開啟檔案 | 使用預設軟體開啟 |
| `` i `` | 忽略或排除檔案 | |
| `` I `` | Add extension to .gitignore | |
| `` r `` | 重新整理檔案 | |
| `` s `` | 收藏 | Stash all changes. For other variations of stashing, use the view stash options keybinding. |
| `` S `` | 檢視收藏選項 | View stash options (e.g. stash all, stash staged, stash unstaged). |
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ type KeybindingFilesConfig struct {
FindBaseCommitForFixup string `yaml:"findBaseCommitForFixup"`
ConfirmDiscard string `yaml:"confirmDiscard"`
IgnoreFile string `yaml:"ignoreFile"`
IgnoreFileExtension string `yaml:"ignoreFileExtension"`
RefreshFiles string `yaml:"refreshFiles"`
StashAllChanges string `yaml:"stashAllChanges"`
ViewStashOptions string `yaml:"viewStashOptions"`
Expand Down Expand Up @@ -928,6 +929,7 @@ func GetDefaultConfig() *UserConfig {
CommitChangesWithEditor: "C",
FindBaseCommitForFixup: "<c-f>",
IgnoreFile: "i",
IgnoreFileExtension: "I",
RefreshFiles: "r",
StashAllChanges: "s",
ViewStashOptions: "S",
Expand Down
34 changes: 34 additions & 0 deletions pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
Description: self.c.Tr.Actions.IgnoreExcludeFile,
OpensMenu: true,
},
{
Key: opts.GetKey(opts.Config.Files.IgnoreFileExtension),
Handler: self.withItem(self.ignoreExtension),
GetDisabledReason: self.require(self.singleItemSelected()),
Description: self.c.Tr.IgnoreFileExtension,
},
{
Key: opts.GetKey(opts.Config.Files.RefreshFiles),
Handler: self.refresh,
Expand Down Expand Up @@ -657,6 +663,24 @@ func (self *FilesController) ignore(node *filetree.FileNode) error {
return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, self.c.Git().WorkingTree.Ignore)
}

func (self *FilesController) ignoreExtension(node *filetree.FileNode) error {
if node.GetPath() == ".gitignore" {
return errors.New(self.c.Tr.Actions.IgnoreFileErr)
}

path := node.GetPath()
ext := filepath.Ext(path)
if ext == "" {
return fmt.Errorf("No file extension to ignore")
}

pattern := "*" + ext

return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, func(string) error {
return self.c.Git().WorkingTree.Ignore(pattern)
})
}

func (self *FilesController) exclude(node *filetree.FileNode) error {
if node.GetPath() == ".gitignore" {
return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)
Expand All @@ -679,6 +703,16 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
},
Key: 'i',
},
{
LabelColumns: []string{self.c.Tr.IgnoreFileExtension},
OnPress: func() error {
if err := self.ignoreExtension(node); err != nil {
return err
}
return nil
},
Key: 'I',
},
{
LabelColumns: []string{self.c.Tr.ExcludeFile},
OnPress: func() error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ type TranslationSet struct {
OpenFileTooltip string
OpenInEditor string
IgnoreFile string
IgnoreFileExtension string
ExcludeFile string
RefreshFiles string
Merge string
Expand Down Expand Up @@ -1291,6 +1292,7 @@ func EnglishTranslationSet() *TranslationSet {
OpenFileTooltip: "Open file in default application.",
OpenInEditor: "Open in editor",
IgnoreFile: `Add to .gitignore`,
IgnoreFileExtension: `Add extension to .gitignore`,
ExcludeFile: `Add to .git/info/exclude`,
RefreshFiles: `Refresh files`,
Merge: `Merge`,
Expand Down
4 changes: 4 additions & 0 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@
"type": "string",
"default": "i"
},
"ignoreFileExtension": {
"type": "string",
"default": "I"
},
"refreshFiles": {
"type": "string",
"default": "r"
Expand Down