git-remote-entire: add --version and --help flags. · Entire
git-remote-entire: add --version and --help flags.
7cfeb0d→main·
toothbrush·1mo ago·2 files·+70 added/-0 removed
Only activate when passed as the sole argument; git always invokes the
helper as git-remote-entire <remote> <url>, so these never collide.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
f93ae52c253aView transcript
Changes
2
cmd/git-remote-entire
Mmain.go+34
Mmain_test.go+36
26 unmodified lines
27
28
29
30
31
32
33
17 unmodified lines
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
76 unmodified lines
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
26 unmodified lines
"net/url"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
17 unmodified lines
}
func run(args []string) int {
// --version / --help only activate as the sole argument. Git always invokes
// the helper as `git-remote-entire <remote-name> <url>` (two args), so these
// can never collide with a real remote-helper invocation.
if len(args) == 2 {
if text, ok := infoFlagText(args[1], loadedVersion()); ok {
fmt.Fprint(os.Stdout, text)
return 0
}
}
if len(args) < 3 {
fmt.Fprintf(os.Stderr, "usage: %s <remote-name> <url>\n", remotehelper.BinaryName)
return 128
}
return 0
}
// loadedVersion populates the build info and returns the resolved version.
func loadedVersion() string {
versioninfo.Load()
return versioninfo.Version
}
// infoFlagText renders the output for the standalone --version / --help flags,
// returning false for anything else. Kept pure (version passed in, no globals)
// so it's unit-testable.
func infoFlagText(flag, version string) (string, bool) {
switch flag {
case "--version":
return fmt.Sprintf("%s %s\nGo version: %s\nOS/Arch: %s/%s\n",
re remotehelper.BinaryName, version, runtime.Version(), runtime.GOOS, runtime.GOARCH), true
case "--help":
return fmt.Sprintf("%s %s\n\n"+
"This is a helper which Git calls when encountering entire://... URLs. "+
"For more information see https://github.com/entireio/cli.\n",
re remotehelper.BinaryName, version), true
}
return "", false
}
// resolveProtocolVersion reads the effective protocol.version from
// the GIT_PROTOCOL environment variable. The value is a colon-
// separated list of key=value pairs (e.g. "version=2"). We accept
Mcmd/git-remote-entire/main.go+34
14 unmodified lines
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
14 unmodified lines
"github.com/entireio/cli/cmd/entire/cli/auth" )
func TestInfoFlagText(t *testing.T) { t.Parallel() tests := []struct { name string flag string want bool contains []string }{ {"version", "--version", true, []string{"git-remote-entire 1.2.3", "Go version:", "OS/Arch:"}}, {"help", "--help", true, []string{"git-remote-entire 1.2.3", "entire://", "https://github.com/entireio/cli"}}, {"unknown flag", "--nope", false, nil}, {"empty", "", false, nil}, {"url-like arg", "entire://host/p/r", false, nil}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() text, ok := infoFlagText(tc.flag, "1.2.3") if ok != tc.want { t.Fatalf("infoFlagText(%q) ok = %v, want %v", tc.flag, ok, tc.want) } if !ok { if text != "" { t.Fatalf("expected empty text when not handled, got %q", text) } return } for _, sub := range tc.contains { if !strings.Contains(text, sub) { t.Errorf("infoFlagText(%q) = %q, missing %q", tc.flag, text, sub) } } } } }
func TestParseProtocolVersion(t *testing.T) { t.Parallel() tests := []struct {