Skip to content

Commit

Permalink
Guess remote from current branch
Browse files Browse the repository at this point in the history
This PR adds the configuration option `core.remote_from_branch`.
If set, the default remote is inferred from the current checked-out branch.

If unset or if `core.default_remote` is set, the behaviour is unchanged.

Fixes: #896
  • Loading branch information
glemco committed Dec 24, 2024
1 parent 29804ac commit e3e83d3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func guessDefaultRemote() string {
if defaultRemote != "" {
return defaultRemote
}
remoteFromBranch := config.GetBool("core.remote_from_branch")
currentBranch, err := git.CurrentBranch()
if remoteFromBranch && err == nil {
remoteConf := fmt.Sprintf("branch.%s.remote", currentBranch)
if remote, err := gitconfig.Local(remoteConf); err == nil {
return remote
}
}
}

guess := ""
Expand Down

0 comments on commit e3e83d3

Please sign in to comment.