-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (71 loc) · 1.66 KB
/
main.go
File metadata and controls
82 lines (71 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"errors"
"fmt"
"os"
"strconv"
"github.com/go-git/go-git/v6/plumbing/transport"
"github.com/go-git/go-git/v6/plumbing/transport/ssh"
"github.com/go-git/go-git/v6/utils/trace"
"github.com/spf13/cobra"
gossh "golang.org/x/crypto/ssh"
)
var rootCmd = &cobra.Command{
Use: "gogit [<args>] <command>",
Short: "gogit is a Git CLI that uses go-git as its backend.",
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Usage()
},
DisableFlagsInUseLine: true,
}
// envToTarget maps what environment variables can be used
// to enable specific trace targets.
var envToTarget = map[string]trace.Target{
"GIT_TRACE": trace.General,
"GIT_TRACE_PACKET": trace.Packet,
"GIT_TRACE_SSH": trace.SSH,
"GIT_TRACE_PERFORMANCE": trace.Performance,
}
func init() {
// Set up tracing
var target trace.Target
for k, v := range envToTarget {
if ok, _ := strconv.ParseBool(os.Getenv(k)); ok {
target |= v
}
}
trace.SetTarget(target)
}
func main() {
if err := rootCmd.Execute(); err != nil {
var rerr *transport.RemoteError
if errors.As(err, &rerr) {
fmt.Fprintln(os.Stderr, rerr)
} else {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}
func defaultAuth(ep *transport.Endpoint) transport.AuthMethod {
switch ep.Scheme {
case "file", "git":
// Do nothing.
case "ssh":
if ep.User == nil {
return nil
}
a, err := ssh.NewSSHAgentAuth(ep.User.Username())
if err != nil {
return nil
}
switch ep.Host {
case "localhost", "127.0.0.1":
// Ignore host key verification for localhost.
a.HostKeyCallback = gossh.InsecureIgnoreHostKey()
}
return a
case "http", "https":
}
return nil
}