@@ -4,24 +4,17 @@ import (
44 "context"
55 "errors"
66 "fmt"
7- "net"
87 "os"
98 "os/signal"
109 "runtime"
1110 "strings"
1211 "syscall"
1312
1413 "github.com/entireio/cli/cmd/entire/cli"
15- "github.com/go-git/go-git/v6/config"
16- "github.com/go-git/go-git/v6/x/plugin"
17- "github.com/go-git/x/plugin/objectsigner/auto"
1814 "github.com/spf13/cobra"
19- "golang.org/x/crypto/ssh/agent"
2015)
2116
2217func main () {
23- registerObjectSigner ()
24-
2518 // Create context that cancels on interrupt
2619 ctx , cancel := context .WithCancel (context .Background ())
2720
@@ -58,81 +51,6 @@ func main() {
5851 cancel () // Cleanup on successful exit
5952}
6053
61- func registerObjectSigner () {
62- //nolint:errcheck,gosec // best-effort; if registration fails, commits are left unsigned
63- plugin .Register (plugin .ObjectSigner (), func () plugin.Signer {
64- cfgSource , err := plugin .Get (plugin .ConfigLoader ())
65- if err != nil {
66- // No config loader registered; signing not possible.
67- return nil
68- }
69-
70- sysCfg := loadScopedConfig (cfgSource , config .SystemScope )
71- globalCfg := loadScopedConfig (cfgSource , config .GlobalScope )
72-
73- // Merge system then global so that global settings take precedence.
74- merged := config .Merge (sysCfg , globalCfg )
75-
76- if ! merged .Commit .GpgSign .IsTrue () {
77- return nil
78- }
79-
80- cfg := auto.Config {
81- SigningKey : merged .User .SigningKey ,
82- Format : auto .Format (merged .GPG .Format ),
83- SSHAgent : connectSSHAgent (),
84- }
85-
86- signer , err := auto .FromConfig (cfg )
87- if err != nil {
88- fmt .Fprintf (os .Stderr , "warning: failed to create object signer: %v\n " , err )
89- return nil
90- }
91-
92- return signer
93- })
94- }
95-
96- // connectSSHAgent connects to the SSH agent via SSH_AUTH_SOCK.
97- // Returns nil if the agent is unavailable.
98- func connectSSHAgent () agent.Agent { //nolint:ireturn // must return the ssh agent interface
99- sock := os .Getenv ("SSH_AUTH_SOCK" )
100- if sock == "" {
101- return nil
102- }
103-
104- var d net.Dialer
105- conn , err := d .DialContext (context .Background (), "unix" , sock )
106- if err != nil {
107- return nil
108- }
109-
110- return agent .NewClient (conn )
111- }
112-
113- var scopeName = map [config.Scope ]string {
114- config .GlobalScope : "global" ,
115- config .SystemScope : "system" ,
116- }
117-
118- func loadScopedConfig (source plugin.ConfigSource , scope config.Scope ) * config.Config {
119- name := scopeName [scope ]
120-
121- storer , err := source .Load (scope )
122- if err != nil {
123- fmt .Fprintf (os .Stderr , "warning: failed to load %s git config: %v\n " , name , err )
124- return config .NewConfig ()
125- }
126-
127- cfg , err := storer .Config ()
128- if err != nil {
129- fmt .Fprintf (os .Stderr , "warning: failed to parse %s git config: %v\n " , name , err )
130- return config .NewConfig ()
131- }
132-
133- return cfg
134- }
135-
13654func showSuggestion (cmd * cobra.Command , err error ) {
13755 // Print usage first (brew style)
13856 fmt .Fprint (cmd .OutOrStderr (), cmd .UsageString ())
0 commit comments