mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-28 09:08:41 +02:00
Implement a sort order menu for remote branches
This commit is contained in:
parent
66b608b2f9
commit
3fe491fcb2
@ -258,6 +258,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
|||||||
<kbd>r</kbd>: Rebase checked-out branch onto this branch
|
<kbd>r</kbd>: Rebase checked-out branch onto this branch
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: Set as upstream of checked-out branch
|
<kbd>u</kbd>: Set as upstream of checked-out branch
|
||||||
|
<kbd>s</kbd>: Sort order
|
||||||
<kbd>g</kbd>: View reset options
|
<kbd>g</kbd>: View reset options
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: View commits
|
<kbd><enter></kbd>: View commits
|
||||||
|
@ -323,6 +323,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
|||||||
<kbd>r</kbd>: Rebase checked-out branch onto this branch
|
<kbd>r</kbd>: Rebase checked-out branch onto this branch
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: Set as upstream of checked-out branch
|
<kbd>u</kbd>: Set as upstream of checked-out branch
|
||||||
|
<kbd>s</kbd>: 並び替え
|
||||||
<kbd>g</kbd>: View reset options
|
<kbd>g</kbd>: View reset options
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: コミットを閲覧
|
<kbd><enter></kbd>: コミットを閲覧
|
||||||
|
@ -241,6 +241,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
|||||||
<kbd>r</kbd>: 체크아웃된 브랜치를 이 브랜치에 리베이스
|
<kbd>r</kbd>: 체크아웃된 브랜치를 이 브랜치에 리베이스
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: Set as upstream of checked-out branch
|
<kbd>u</kbd>: Set as upstream of checked-out branch
|
||||||
|
<kbd>s</kbd>: Sort order
|
||||||
<kbd>g</kbd>: View reset options
|
<kbd>g</kbd>: View reset options
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: 커밋 보기
|
<kbd><enter></kbd>: 커밋 보기
|
||||||
|
@ -236,6 +236,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
|||||||
<kbd>r</kbd>: Rebase branch
|
<kbd>r</kbd>: Rebase branch
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: Stel in als upstream van uitgecheckte branch
|
<kbd>u</kbd>: Stel in als upstream van uitgecheckte branch
|
||||||
|
<kbd>s</kbd>: Sort order
|
||||||
<kbd>g</kbd>: Bekijk reset opties
|
<kbd>g</kbd>: Bekijk reset opties
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: Bekijk commits
|
<kbd><enter></kbd>: Bekijk commits
|
||||||
|
@ -235,6 +235,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
|||||||
<kbd>r</kbd>: Zmiana bazy gałęzi
|
<kbd>r</kbd>: Zmiana bazy gałęzi
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: Set as upstream of checked-out branch
|
<kbd>u</kbd>: Set as upstream of checked-out branch
|
||||||
|
<kbd>s</kbd>: Sort order
|
||||||
<kbd>g</kbd>: Wyświetl opcje resetu
|
<kbd>g</kbd>: Wyświetl opcje resetu
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: View commits
|
<kbd><enter></kbd>: View commits
|
||||||
|
@ -296,6 +296,7 @@ _Связки клавиш_
|
|||||||
<kbd>r</kbd>: Перебазировать переключённую ветку на эту ветку
|
<kbd>r</kbd>: Перебазировать переключённую ветку на эту ветку
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: Установить как upstream-ветку переключённую ветку
|
<kbd>u</kbd>: Установить как upstream-ветку переключённую ветку
|
||||||
|
<kbd>s</kbd>: Порядок сортировки
|
||||||
<kbd>g</kbd>: Просмотреть параметры сброса
|
<kbd>g</kbd>: Просмотреть параметры сброса
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: Просмотреть коммиты
|
<kbd><enter></kbd>: Просмотреть коммиты
|
||||||
|
@ -337,6 +337,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
|||||||
<kbd>r</kbd>: 将已检出的分支变基到该分支
|
<kbd>r</kbd>: 将已检出的分支变基到该分支
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: 设置为检出分支的上游
|
<kbd>u</kbd>: 设置为检出分支的上游
|
||||||
|
<kbd>s</kbd>: Sort order
|
||||||
<kbd>g</kbd>: 查看重置选项
|
<kbd>g</kbd>: 查看重置选项
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: 查看提交
|
<kbd><enter></kbd>: 查看提交
|
||||||
|
@ -347,6 +347,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B_
|
|||||||
<kbd>r</kbd>: 將已檢出的分支變基至此分支
|
<kbd>r</kbd>: 將已檢出的分支變基至此分支
|
||||||
<kbd>d</kbd>: Delete remote tag
|
<kbd>d</kbd>: Delete remote tag
|
||||||
<kbd>u</kbd>: 將此分支設為當前分支之上游
|
<kbd>u</kbd>: 將此分支設為當前分支之上游
|
||||||
|
<kbd>s</kbd>: Sort order
|
||||||
<kbd>g</kbd>: 檢視重設選項
|
<kbd>g</kbd>: 檢視重設選項
|
||||||
<kbd>w</kbd>: View worktree options
|
<kbd>w</kbd>: View worktree options
|
||||||
<kbd><enter></kbd>: 檢視提交
|
<kbd><enter></kbd>: 檢視提交
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -83,14 +84,23 @@ func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) {
|
|||||||
func (self *RemoteLoader) getRemoteBranchesByRemoteName() (map[string][]*models.RemoteBranch, error) {
|
func (self *RemoteLoader) getRemoteBranchesByRemoteName() (map[string][]*models.RemoteBranch, error) {
|
||||||
remoteBranchesByRemoteName := make(map[string][]*models.RemoteBranch)
|
remoteBranchesByRemoteName := make(map[string][]*models.RemoteBranch)
|
||||||
|
|
||||||
cmdArgs := NewGitCmd("branch").Arg("-r").ToArgv()
|
var sortOrder string
|
||||||
err := self.cmd.New(cmdArgs).DontLog().RunAndProcessLines(func(line string) (bool, error) {
|
switch strings.ToLower(self.AppState.RemoteBranchSortOrder) {
|
||||||
// excluding lines like 'origin/HEAD -> origin/master' (there will be a separate
|
case "alphabetical":
|
||||||
// line for 'origin/master')
|
sortOrder = "refname"
|
||||||
if strings.Contains(line, "->") {
|
case "date":
|
||||||
return false, nil
|
sortOrder = "-committerdate"
|
||||||
}
|
default:
|
||||||
|
sortOrder = "refname"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdArgs := NewGitCmd("for-each-ref").
|
||||||
|
Arg(fmt.Sprintf("--sort=%s", sortOrder)).
|
||||||
|
Arg("--format=%(refname:short)").
|
||||||
|
Arg("refs/remotes").
|
||||||
|
ToArgv()
|
||||||
|
|
||||||
|
err := self.cmd.New(cmdArgs).DontLog().RunAndProcessLines(func(line string) (bool, error) {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
|
|
||||||
split := strings.SplitN(line, "/", 2)
|
split := strings.SplitN(line, "/", 2)
|
||||||
|
@ -323,14 +323,16 @@ type AppState struct {
|
|||||||
HideCommandLog bool
|
HideCommandLog bool
|
||||||
IgnoreWhitespaceInDiffView bool
|
IgnoreWhitespaceInDiffView bool
|
||||||
DiffContextSize int
|
DiffContextSize int
|
||||||
|
RemoteBranchSortOrder string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultAppState() *AppState {
|
func getDefaultAppState() *AppState {
|
||||||
return &AppState{
|
return &AppState{
|
||||||
LastUpdateCheck: 0,
|
LastUpdateCheck: 0,
|
||||||
RecentRepos: []string{},
|
RecentRepos: []string{},
|
||||||
StartupPopupVersion: 0,
|
StartupPopupVersion: 0,
|
||||||
DiffContextSize: 3,
|
DiffContextSize: 3,
|
||||||
|
RemoteBranchSortOrder: "alphabetical",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,6 +389,7 @@ type KeybindingBranchesConfig struct {
|
|||||||
PushTag string `yaml:"pushTag"`
|
PushTag string `yaml:"pushTag"`
|
||||||
SetUpstream string `yaml:"setUpstream"`
|
SetUpstream string `yaml:"setUpstream"`
|
||||||
FetchRemote string `yaml:"fetchRemote"`
|
FetchRemote string `yaml:"fetchRemote"`
|
||||||
|
SortOrder string `yaml:"sortOrder"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeybindingWorktreesConfig struct {
|
type KeybindingWorktreesConfig struct {
|
||||||
@ -781,6 +782,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
PushTag: "P",
|
PushTag: "P",
|
||||||
SetUpstream: "u",
|
SetUpstream: "u",
|
||||||
FetchRemote: "f",
|
FetchRemote: "f",
|
||||||
|
SortOrder: "s",
|
||||||
},
|
},
|
||||||
Worktrees: KeybindingWorktreesConfig{
|
Worktrees: KeybindingWorktreesConfig{
|
||||||
ViewWorktreeOptions: "w",
|
ViewWorktreeOptions: "w",
|
||||||
|
@ -119,6 +119,37 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *RefsHelper) CreateSortOrderMenu(onSelected func(sortOrder string) error) error {
|
||||||
|
type sortOrderWithKey struct {
|
||||||
|
key types.Key
|
||||||
|
label string
|
||||||
|
sortKey string
|
||||||
|
sortOrder string
|
||||||
|
}
|
||||||
|
sortKeys := []sortOrderWithKey{
|
||||||
|
{label: self.c.Tr.SortAlphabetical, sortKey: "refname", sortOrder: "alphabetical", key: 'a'},
|
||||||
|
{label: self.c.Tr.SortByDate, sortKey: "-committerdate", sortOrder: "date", key: 'd'},
|
||||||
|
}
|
||||||
|
|
||||||
|
menuItems := lo.Map(sortKeys, func(row sortOrderWithKey, _ int) *types.MenuItem {
|
||||||
|
return &types.MenuItem{
|
||||||
|
LabelColumns: []string{
|
||||||
|
row.label,
|
||||||
|
style.FgYellow.Sprintf("--sort=%s", row.sortKey),
|
||||||
|
},
|
||||||
|
OnPress: func() error {
|
||||||
|
return onSelected(row.sortOrder)
|
||||||
|
},
|
||||||
|
Key: row.key,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return self.c.Menu(types.CreateMenuOptions{
|
||||||
|
Title: self.c.Tr.SortOrder,
|
||||||
|
Items: menuItems,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (self *RefsHelper) CreateGitResetMenu(ref string) error {
|
func (self *RefsHelper) CreateGitResetMenu(ref string) error {
|
||||||
type strengthWithKey struct {
|
type strengthWithKey struct {
|
||||||
strength string
|
strength string
|
||||||
|
@ -58,6 +58,12 @@ func (self *RemoteBranchesController) GetKeybindings(opts types.KeybindingsOpts)
|
|||||||
Handler: self.checkSelected(self.setAsUpstream),
|
Handler: self.checkSelected(self.setAsUpstream),
|
||||||
Description: self.c.Tr.SetAsUpstream,
|
Description: self.c.Tr.SetAsUpstream,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: opts.GetKey(opts.Config.Branches.SortOrder),
|
||||||
|
Handler: self.createSortMenu,
|
||||||
|
Description: self.c.Tr.SortOrder,
|
||||||
|
OpensMenu: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
|
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
|
||||||
Handler: self.checkSelected(self.createResetMenu),
|
Handler: self.checkSelected(self.createResetMenu),
|
||||||
@ -121,6 +127,18 @@ func (self *RemoteBranchesController) rebase(selectedBranch *models.RemoteBranch
|
|||||||
return self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranch.FullName())
|
return self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranch.FullName())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *RemoteBranchesController) createSortMenu() error {
|
||||||
|
return self.c.Helpers().Refs.CreateSortOrderMenu(func(sortOrder string) error {
|
||||||
|
if self.c.GetAppState().RemoteBranchSortOrder != sortOrder {
|
||||||
|
self.c.GetAppState().RemoteBranchSortOrder = sortOrder
|
||||||
|
self.c.SaveAppStateAndLogError()
|
||||||
|
self.c.Contexts().RemoteBranches.SetSelectedLineIdx(0)
|
||||||
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.REMOTES}})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (self *RemoteBranchesController) createResetMenu(selectedBranch *models.RemoteBranch) error {
|
func (self *RemoteBranchesController) createResetMenu(selectedBranch *models.RemoteBranch) error {
|
||||||
return self.c.Helpers().Refs.CreateGitResetMenu(selectedBranch.FullName())
|
return self.c.Helpers().Refs.CreateGitResetMenu(selectedBranch.FullName())
|
||||||
}
|
}
|
||||||
|
@ -555,6 +555,9 @@ type TranslationSet struct {
|
|||||||
LogMenuTitle string
|
LogMenuTitle string
|
||||||
ToggleShowGitGraphAll string
|
ToggleShowGitGraphAll string
|
||||||
ShowGitGraph string
|
ShowGitGraph string
|
||||||
|
SortOrder string
|
||||||
|
SortAlphabetical string
|
||||||
|
SortByDate string
|
||||||
SortCommits string
|
SortCommits string
|
||||||
CantChangeContextSizeError string
|
CantChangeContextSizeError string
|
||||||
OpenCommitInBrowser string
|
OpenCommitInBrowser string
|
||||||
@ -1364,6 +1367,9 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
LogMenuTitle: "Commit Log Options",
|
LogMenuTitle: "Commit Log Options",
|
||||||
ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)",
|
ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)",
|
||||||
ShowGitGraph: "Show git graph",
|
ShowGitGraph: "Show git graph",
|
||||||
|
SortOrder: "Sort order",
|
||||||
|
SortAlphabetical: "Alphabetical",
|
||||||
|
SortByDate: "Date",
|
||||||
SortCommits: "Commit sort order",
|
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!",
|
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",
|
OpenCommitInBrowser: "Open commit in browser",
|
||||||
|
@ -461,8 +461,11 @@ func japaneseTranslationSet() TranslationSet {
|
|||||||
OpenLogMenu: "ログメニューを開く",
|
OpenLogMenu: "ログメニューを開く",
|
||||||
LogMenuTitle: "コミットログオプション",
|
LogMenuTitle: "コミットログオプション",
|
||||||
// ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)",
|
// ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)",
|
||||||
ShowGitGraph: "コミットグラフの表示",
|
ShowGitGraph: "コミットグラフの表示",
|
||||||
SortCommits: "コミットの表示順",
|
SortOrder: "並び替え",
|
||||||
|
SortAlphabetical: "アルファベット順",
|
||||||
|
SortByDate: "日付順",
|
||||||
|
SortCommits: "コミットの表示順",
|
||||||
// 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!",
|
// 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: "ブラウザでコミットを開く",
|
OpenCommitInBrowser: "ブラウザでコミットを開く",
|
||||||
// LcViewBisectOptions: "View bisect options",
|
// LcViewBisectOptions: "View bisect options",
|
||||||
|
@ -525,6 +525,9 @@ func RussianTranslationSet() TranslationSet {
|
|||||||
LogMenuTitle: "Параметры журнала коммитов",
|
LogMenuTitle: "Параметры журнала коммитов",
|
||||||
ToggleShowGitGraphAll: "Переключить отображение всего git графа (передать флаг --all в git log )",
|
ToggleShowGitGraphAll: "Переключить отображение всего git графа (передать флаг --all в git log )",
|
||||||
ShowGitGraph: "Показать git граф",
|
ShowGitGraph: "Показать git граф",
|
||||||
|
SortOrder: "Порядок сортировки",
|
||||||
|
SortAlphabetical: "По алфавиту",
|
||||||
|
SortByDate: "По дате",
|
||||||
SortCommits: "Упорядочить коммиты",
|
SortCommits: "Упорядочить коммиты",
|
||||||
CantChangeContextSizeError: "Невозможно изменить контекст в режиме создания патча, потому что мы были слишком ленивы, чтобы поддерживать его при выпуске функции. Если вы действительно этого хотите, пожалуйста, дайте нам знать!",
|
CantChangeContextSizeError: "Невозможно изменить контекст в режиме создания патча, потому что мы были слишком ленивы, чтобы поддерживать его при выпуске функции. Если вы действительно этого хотите, пожалуйста, дайте нам знать!",
|
||||||
OpenCommitInBrowser: "Открыть коммит в браузере",
|
OpenCommitInBrowser: "Открыть коммит в браузере",
|
||||||
|
@ -1014,6 +1014,10 @@
|
|||||||
"fetchRemote": {
|
"fetchRemote": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "f"
|
"default": "f"
|
||||||
|
},
|
||||||
|
"sortOrder": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "s"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user