1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

Bump go-git

This commit is contained in:
Stefan Haller
2025-04-09 10:38:46 +02:00
parent da0105c16b
commit 4cf49ff449
527 changed files with 70489 additions and 10167 deletions

View File

@@ -1,5 +1,9 @@
Carlos A Becker <caarlos0@gmail.com>
Dustin Spicuzza <dustin@virtualroadside.com>
Eugene Terentev <eugene@terentev.net>
Kevin Burke <kevin@burke.dev>
Mark Nevill <nev@improbable.io>
Scott Lessans <slessans@gmail.com>
Sergey Lukjanov <me@slukjanov.name>
Wayne Ashley Berry <wayneashleyberry@gmail.com>
santosh653 <70637961+santosh653@users.noreply.github.com>

19
vendor/github.com/kevinburke/ssh_config/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,19 @@
# Changes
## Version 1.2
Previously, if a Host declaration or a value had trailing whitespace, that
whitespace would have been included as part of the value. This led to unexpected
consequences. For example:
```
Host example # A comment
HostName example.com # Another comment
```
Prior to version 1.2, the value for Host would have been "example " and the
value for HostName would have been "example.com ". Both of these are
unintuitive.
Instead, we strip the trailing whitespace in the configuration, which leads to
more intuitive behavior.

View File

@@ -19,8 +19,11 @@ race-test: lint
$(BUMP_VERSION):
go get -u github.com/kevinburke/bump_version
$(WRITE_MAILMAP):
go get -u github.com/kevinburke/write_mailmap
release: test | $(BUMP_VERSION)
$(BUMP_VERSION) minor config.go
$(BUMP_VERSION) --tag-prefix=v minor config.go
force: ;

View File

@@ -17,6 +17,14 @@ want to retrieve.
port := ssh_config.Get("myhost", "Port")
```
Certain directives can occur multiple times for a host (such as `IdentityFile`),
so you should use the `GetAll` or `GetAllStrict` directive to retrieve those
instead.
```go
files := ssh_config.GetAll("myhost", "IdentityFile")
```
You can also load a config file and read values from it.
```go
@@ -76,6 +84,9 @@ file format.
## Donating
Donations free up time to make improvements to the library, and respond to
bug reports. You can send donations via Paypal's "Send Money" feature to
kev@inburke.com. Donations are not tax deductible in the USA.
I don't get paid to maintain this project. Donations free up time to make
improvements to the library, and respond to bug reports. You can send donations
via Paypal's "Send Money" feature to kev@inburke.com. Donations are not tax
deductible in the USA.
You can also reach out about a consulting engagement: https://burke.services

View File

@@ -34,7 +34,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
osuser "os/user"
"path/filepath"
@@ -44,7 +43,7 @@ import (
"sync"
)
const version = "1.0"
const version = "1.2"
var _ = version
@@ -102,6 +101,13 @@ func findVal(c *Config, alias, key string) (string, error) {
return val, nil
}
func findAll(c *Config, alias, key string) ([]string, error) {
if c == nil {
return nil, nil
}
return c.GetAll(alias, key)
}
// Get finds the first value for key within a declaration that matches the
// alias. Get returns the empty string if no value was found, or if IgnoreErrors
// is false and we could not parse the configuration file. Use GetStrict to
@@ -114,19 +120,51 @@ func Get(alias, key string) string {
return DefaultUserSettings.Get(alias, key)
}
// GetAll retrieves zero or more directives for key for the given alias. GetAll
// returns nil if no value was found, or if IgnoreErrors is false and we could
// not parse the configuration file. Use GetAllStrict to disambiguate the
// latter cases.
//
// In most cases you want to use Get or GetStrict, which returns a single value.
// However, a subset of ssh configuration values (IdentityFile, for example)
// allow you to specify multiple directives.
//
// The match for key is case insensitive.
//
// GetAll is a wrapper around DefaultUserSettings.GetAll.
func GetAll(alias, key string) []string {
return DefaultUserSettings.GetAll(alias, key)
}
// GetStrict finds the first value for key within a declaration that matches the
// alias. If key has a default value and no matching configuration is found, the
// default will be returned. For more information on default values and the way
// patterns are matched, see the manpage for ssh_config.
//
// error will be non-nil if and only if a user's configuration file or the
// system configuration file could not be parsed, and u.IgnoreErrors is false.
// The returned error will be non-nil if and only if a user's configuration file
// or the system configuration file could not be parsed, and u.IgnoreErrors is
// false.
//
// GetStrict is a wrapper around DefaultUserSettings.GetStrict.
func GetStrict(alias, key string) (string, error) {
return DefaultUserSettings.GetStrict(alias, key)
}
// GetAllStrict retrieves zero or more directives for key for the given alias.
//
// In most cases you want to use Get or GetStrict, which returns a single value.
// However, a subset of ssh configuration values (IdentityFile, for example)
// allow you to specify multiple directives.
//
// The returned error will be non-nil if and only if a user's configuration file
// or the system configuration file could not be parsed, and u.IgnoreErrors is
// false.
//
// GetAllStrict is a wrapper around DefaultUserSettings.GetAllStrict.
func GetAllStrict(alias, key string) ([]string, error) {
return DefaultUserSettings.GetAllStrict(alias, key)
}
// Get finds the first value for key within a declaration that matches the
// alias. Get returns the empty string if no value was found, or if IgnoreErrors
// is false and we could not parse the configuration file. Use GetStrict to
@@ -141,6 +179,17 @@ func (u *UserSettings) Get(alias, key string) string {
return val
}
// GetAll retrieves zero or more directives for key for the given alias. GetAll
// returns nil if no value was found, or if IgnoreErrors is false and we could
// not parse the configuration file. Use GetStrict to disambiguate the latter
// cases.
//
// The match for key is case insensitive.
func (u *UserSettings) GetAll(alias, key string) []string {
val, _ := u.GetAllStrict(alias, key)
return val
}
// GetStrict finds the first value for key within a declaration that matches the
// alias. If key has a default value and no matching configuration is found, the
// default will be returned. For more information on default values and the way
@@ -149,6 +198,52 @@ func (u *UserSettings) Get(alias, key string) string {
// error will be non-nil if and only if a user's configuration file or the
// system configuration file could not be parsed, and u.IgnoreErrors is false.
func (u *UserSettings) GetStrict(alias, key string) (string, error) {
u.doLoadConfigs()
//lint:ignore S1002 I prefer it this way
if u.onceErr != nil && u.IgnoreErrors == false {
return "", u.onceErr
}
val, err := findVal(u.userConfig, alias, key)
if err != nil || val != "" {
return val, err
}
val2, err2 := findVal(u.systemConfig, alias, key)
if err2 != nil || val2 != "" {
return val2, err2
}
return Default(key), nil
}
// GetAllStrict retrieves zero or more directives for key for the given alias.
// If key has a default value and no matching configuration is found, the
// default will be returned. For more information on default values and the way
// patterns are matched, see the manpage for ssh_config.
//
// The returned error will be non-nil if and only if a user's configuration file
// or the system configuration file could not be parsed, and u.IgnoreErrors is
// false.
func (u *UserSettings) GetAllStrict(alias, key string) ([]string, error) {
u.doLoadConfigs()
//lint:ignore S1002 I prefer it this way
if u.onceErr != nil && u.IgnoreErrors == false {
return nil, u.onceErr
}
val, err := findAll(u.userConfig, alias, key)
if err != nil || val != nil {
return val, err
}
val2, err2 := findAll(u.systemConfig, alias, key)
if err2 != nil || val2 != nil {
return val2, err2
}
// TODO: IdentityFile has multiple default values that we should return.
if def := Default(key); def != "" {
return []string{def}, nil
}
return []string{}, nil
}
func (u *UserSettings) doLoadConfigs() {
u.loadConfigs.Do(func() {
// can't parse user file, that's ok.
var filename string
@@ -176,19 +271,6 @@ func (u *UserSettings) GetStrict(alias, key string) (string, error) {
return
}
})
//lint:ignore S1002 I prefer it this way
if u.onceErr != nil && u.IgnoreErrors == false {
return "", u.onceErr
}
val, err := findVal(u.userConfig, alias, key)
if err != nil || val != "" {
return val, err
}
val2, err2 := findVal(u.systemConfig, alias, key)
if err2 != nil || val2 != "" {
return val2, err2
}
return Default(key), nil
}
func parseFile(filename string) (*Config, error) {
@@ -196,7 +278,7 @@ func parseFile(filename string) (*Config, error) {
}
func parseWithDepth(filename string, depth uint8) (*Config, error) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
@@ -211,13 +293,19 @@ func isSystem(filename string) bool {
// Decode reads r into a Config, or returns an error if r could not be parsed as
// an SSH config file.
func Decode(r io.Reader) (*Config, error) {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, err
}
return decodeBytes(b, false, 0)
}
// DecodeBytes reads b into a Config, or returns an error if r could not be
// parsed as an SSH config file.
func DecodeBytes(b []byte) (*Config, error) {
return decodeBytes(b, false, 0)
}
func decodeBytes(b []byte, system bool, depth uint8) (c *Config, err error) {
defer func() {
if r := recover(); r != nil {
@@ -282,6 +370,42 @@ func (c *Config) Get(alias, key string) (string, error) {
return "", nil
}
// GetAll returns all values in the configuration that match the alias and
// contains key, or nil if none are present.
func (c *Config) GetAll(alias, key string) ([]string, error) {
lowerKey := strings.ToLower(key)
all := []string(nil)
for _, host := range c.Hosts {
if !host.Matches(alias) {
continue
}
for _, node := range host.Nodes {
switch t := node.(type) {
case *Empty:
continue
case *KV:
// "keys are case insensitive" per the spec
lkey := strings.ToLower(t.Key)
if lkey == "match" {
panic("can't handle Match directives")
}
if lkey == lowerKey {
all = append(all, t.Value)
}
case *Include:
val, _ := t.GetAll(alias, key)
if len(val) > 0 {
all = append(all, val...)
}
default:
return nil, fmt.Errorf("unknown Node type %v", t)
}
}
}
return all, nil
}
// String returns a string representation of the Config file.
func (c Config) String() string {
return marshal(c).String()
@@ -374,7 +498,10 @@ type Host struct {
// A Node is either a key/value pair or a comment line.
Nodes []Node
// EOLComment is the comment (if any) terminating the Host line.
EOLComment string
EOLComment string
// Whitespace if any between the Host declaration and a trailing comment.
spaceBeforeComment string
hasEquals bool
leadingSpace int // TODO: handle spaces vs tabs here.
// The file starts with an implicit "Host *" declaration.
@@ -406,7 +533,7 @@ func (h *Host) Matches(alias string) bool {
// String prints h as it would appear in a config file. Minor tweaks may be
// present in the whitespace in the printed file.
func (h *Host) String() string {
var buf bytes.Buffer
var buf strings.Builder
//lint:ignore S1002 I prefer to write it this way
if h.implicit == false {
buf.WriteString(strings.Repeat(" ", int(h.leadingSpace)))
@@ -422,8 +549,9 @@ func (h *Host) String() string {
buf.WriteString(" ")
}
}
buf.WriteString(h.spaceBeforeComment)
if h.EOLComment != "" {
buf.WriteString(" #")
buf.WriteByte('#')
buf.WriteString(h.EOLComment)
}
buf.WriteByte('\n')
@@ -444,12 +572,14 @@ type Node interface {
// KV is a line in the config file that contains a key, a value, and possibly
// a comment.
type KV struct {
Key string
Value string
Comment string
hasEquals bool
leadingSpace int // Space before the key. TODO handle spaces vs tabs.
position Position
Key string
Value string
// Whitespace after the value but before any comment
spaceAfterValue string
Comment string
hasEquals bool
leadingSpace int // Space before the key. TODO handle spaces vs tabs.
position Position
}
// Pos returns k's Position.
@@ -457,8 +587,7 @@ func (k *KV) Pos() Position {
return k.position
}
// String prints k as it was parsed in the config file. There may be slight
// changes to the whitespace between values.
// String prints k as it was parsed in the config file.
func (k *KV) String() string {
if k == nil {
return ""
@@ -467,9 +596,9 @@ func (k *KV) String() string {
if k.hasEquals {
equals = " = "
}
line := fmt.Sprintf("%s%s%s%s", strings.Repeat(" ", int(k.leadingSpace)), k.Key, equals, k.Value)
line := strings.Repeat(" ", int(k.leadingSpace)) + k.Key + equals + k.Value + k.spaceAfterValue
if k.Comment != "" {
line += " #" + k.Comment
line += "#" + k.Comment
}
return line
}
@@ -611,6 +740,31 @@ func (inc *Include) Get(alias, key string) string {
return ""
}
// GetAll finds all values in the Include statement matching the alias and the
// given key.
func (inc *Include) GetAll(alias, key string) ([]string, error) {
inc.mu.Lock()
defer inc.mu.Unlock()
var vals []string
// TODO: we search files in any order which is not correct
for i := range inc.matches {
cfg := inc.files[inc.matches[i]]
if cfg == nil {
panic("nil cfg")
}
val, err := cfg.GetAll(alias, key)
if err == nil && len(val) != 0 {
// In theory if SupportsMultiple was false for this key we could
// stop looking here. But the caller has asked us to find all
// instances of the keyword (and could use Get() if they wanted) so
// let's keep looking.
vals = append(vals, val...)
}
}
return vals, nil
}
// String prints out a string representation of this Include directive. Note
// included Config files are not printed as part of this representation.
func (inc *Include) String() string {

View File

@@ -3,6 +3,7 @@ package ssh_config
import (
"fmt"
"strings"
"unicode"
)
type sshParser struct {
@@ -122,11 +123,16 @@ func (p *sshParser) parseKV() sshParserStateFn {
}
patterns = append(patterns, pat)
}
// val.val at this point could be e.g. "example.com "
hostval := strings.TrimRightFunc(val.val, unicode.IsSpace)
spaceBeforeComment := val.val[len(hostval):]
val.val = hostval
p.config.Hosts = append(p.config.Hosts, &Host{
Patterns: patterns,
Nodes: make([]Node, 0),
EOLComment: comment,
hasEquals: hasEquals,
Patterns: patterns,
Nodes: make([]Node, 0),
EOLComment: comment,
spaceBeforeComment: spaceBeforeComment,
hasEquals: hasEquals,
})
return p.parseStart
}
@@ -144,13 +150,16 @@ func (p *sshParser) parseKV() sshParserStateFn {
lastHost.Nodes = append(lastHost.Nodes, inc)
return p.parseStart
}
shortval := strings.TrimRightFunc(val.val, unicode.IsSpace)
spaceAfterValue := val.val[len(shortval):]
kv := &KV{
Key: key.val,
Value: val.val,
Comment: comment,
hasEquals: hasEquals,
leadingSpace: key.Position.Col - 1,
position: key.Position,
Key: key.val,
Value: shortval,
spaceAfterValue: spaceAfterValue,
Comment: comment,
hasEquals: hasEquals,
leadingSpace: key.Position.Col - 1,
position: key.Position,
}
lastHost.Nodes = append(lastHost.Nodes, kv)
return p.parseStart

View File

@@ -160,3 +160,27 @@ var defaults = map[string]string{
strings.ToLower("VisualHostKey"): "no",
strings.ToLower("XAuthLocation"): "/usr/X11R6/bin/xauth",
}
// these identities are used for SSH protocol 2
var defaultProtocol2Identities = []string{
"~/.ssh/id_dsa",
"~/.ssh/id_ecdsa",
"~/.ssh/id_ed25519",
"~/.ssh/id_rsa",
}
// these directives support multiple items that can be collected
// across multiple files
var pluralDirectives = map[string]bool{
"CertificateFile": true,
"IdentityFile": true,
"DynamicForward": true,
"RemoteForward": true,
"SendEnv": true,
"SetEnv": true,
}
// SupportsMultiple reports whether a directive can be specified multiple times.
func SupportsMultiple(key string) bool {
return pluralDirectives[strings.ToLower(key)]
}