Skip to content
Closed
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 @@ -116,6 +116,7 @@ git:
fetchAll: true # Pass --all flag when running git fetch. Set to false to fetch only origin (or the current branch's upstream remote if there is one)
branchLogCmd: 'git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --'
allBranchesLogCmd: 'git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium'
remoteBranchOrder: 'alphabetical' # one of: 'alphabetical' | 'lastCommit'
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
disableForcePushing: false
parseEmoji: false
Expand Down
16 changes: 15 additions & 1 deletion pkg/commands/git_commands/remote_loader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package git_commands

import (
"fmt"
"strings"
"sync"

Expand Down Expand Up @@ -83,7 +84,20 @@ func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) {
func (self *RemoteLoader) getRemoteBranchesByRemoteName() (map[string][]*models.RemoteBranch, error) {
remoteBranchesByRemoteName := make(map[string][]*models.RemoteBranch)

cmdArgs := NewGitCmd("branch").Arg("-r").ToArgv()
sortOrder := "refname"
switch self.UserConfig.Git.RemoteBranchOrder {
case "alphabetical":
sortOrder = "refname"
case "lastCommit":
sortOrder = "-authordate"
}

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) {
// excluding lines like 'origin/HEAD -> origin/master' (there will be a separate
// line for 'origin/master')
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ type GitConfig struct {
BranchLogCmd string `yaml:"branchLogCmd"`
// Command used to display git log of all branches in the main window
AllBranchesLogCmd string `yaml:"allBranchesLogCmd"`
// One of: 'alphabetical' (default) | 'lastCommit'
RemoteBranchOrder string `yaml:"remoteBranchOrder" jsonschema:"enum=alphabetical,enum=lastCommit"`
// If true, do not spawn a separate process when using GPG
OverrideGpg bool `yaml:"overrideGpg"`
// If true, do not allow force pushes
Expand Down Expand Up @@ -663,6 +665,7 @@ func GetDefaultConfig() *UserConfig {
FetchAll: true,
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium",
RemoteBranchOrder: "alphabetical",
DisableForcePushing: false,
CommitPrefixes: map[string]CommitPrefixConfig(nil),
ParseEmoji: false,
Expand Down
9 changes: 9 additions & 0 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,15 @@
"description": "Command used to display git log of all branches in the main window",
"default": "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium"
},
"remoteBranchOrder": {
"type": "string",
"enum": [
"alphabetical",
"lastCommit"
],
"description": "One of: 'alphabetical' (default) | 'lastCommit'",
"default": "alphabetical"
},
"overrideGpg": {
"type": "boolean",
"description": "If true, do not spawn a separate process when using GPG"
Expand Down