Skip to content

Commit 07ef52e

Browse files
authored
Merge pull request #9 from aymanbagabas/update-v6
Update to use v6
2 parents f9da65d + e5e568f commit 07ef52e

File tree

11 files changed

+218
-59
lines changed

11 files changed

+218
-59
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
# cli
1+
# Go Git CLI
2+
3+
This provides a Go Git CLI binary using `go-git`.
4+
5+
## Installation
6+
7+
```bash
8+
go install github.com/go-git/cli/cmd/gogit
9+
```
10+
11+
## Usage
12+
13+
```bash
14+
gogit <command> [flags]
15+
```
16+
17+
## License
18+
19+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
20+

cmd/ggit/clone.go renamed to cmd/gogit/clone.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package main
22

33
import (
4+
"fmt"
45
"path"
6+
"strings"
57

6-
"github.com/go-git/go-git/v5"
7-
"github.com/go-git/go-git/v5/plumbing/transport"
8+
"github.com/go-git/go-git/v6"
9+
"github.com/go-git/go-git/v6/plumbing/transport"
810
"github.com/spf13/cobra"
911
)
1012

1113
var (
1214
cloneBare bool
1315
cloneProgress bool
1416
cloneDepth int
17+
cloneTags bool
1518
)
1619

1720
func init() {
1821
cloneCmd.Flags().BoolVarP(&cloneBare, "bare", "", false, "Create a bare repository")
1922
cloneCmd.Flags().BoolVarP(&cloneProgress, "progress", "", true, "Show clone progress")
2023
cloneCmd.Flags().IntVarP(&cloneDepth, "depth", "", 0, "Create a shallow clone of that depth")
24+
cloneCmd.Flags().BoolVarP(&cloneTags, "tags", "", false, "Clone tags")
2125
rootCmd.AddCommand(cloneCmd)
2226
rootCmd.CompletionOptions.HiddenDefaultCmd = true
2327
}
@@ -30,6 +34,11 @@ var cloneCmd = &cobra.Command{
3034
dir := path.Base(args[0])
3135
if len(args) > 1 {
3236
dir = args[1]
37+
} else {
38+
dir = strings.TrimSuffix(dir, ".git")
39+
if cloneBare {
40+
dir = dir + ".git"
41+
}
3342
}
3443

3544
ep, err := transport.NewEndpoint(args[0])
@@ -41,13 +50,19 @@ var cloneCmd = &cobra.Command{
4150
URL: args[0],
4251
Depth: cloneDepth,
4352
Auth: defaultAuth(ep),
53+
Bare: cloneBare,
4454
}
4555

56+
if cloneTags {
57+
opts.Tags = git.TagFollowing
58+
}
4659
if cloneProgress {
4760
opts.Progress = cmd.OutOrStdout()
4861
}
4962

50-
_, err = git.PlainClone(dir, cloneBare, &opts)
63+
fmt.Fprintf(cmd.ErrOrStderr(), "Cloning into '%s'...\n", dir) //nolint:errcheck
64+
65+
_, err = git.PlainClone(dir, &opts)
5166
return err
5267
},
5368
DisableFlagsInUseLine: true,

cmd/ggit/fetch.go renamed to cmd/gogit/fetch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"errors"
55
"math"
66

7-
"github.com/go-git/go-git/v5"
8-
"github.com/go-git/go-git/v5/plumbing/transport"
7+
"github.com/go-git/go-git/v6"
8+
"github.com/go-git/go-git/v6/plumbing/transport"
99
"github.com/spf13/cobra"
1010
)
1111

cmd/ggit/main.go renamed to cmd/gogit/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import (
55
"os"
66
"strconv"
77

8-
"github.com/go-git/go-git/v5/plumbing/transport"
9-
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
10-
"github.com/go-git/go-git/v5/utils/trace"
8+
"github.com/go-git/go-git/v6/plumbing/transport"
9+
"github.com/go-git/go-git/v6/plumbing/transport/ssh"
10+
"github.com/go-git/go-git/v6/utils/trace"
1111
"github.com/spf13/cobra"
1212
gossh "golang.org/x/crypto/ssh"
1313
)
1414

1515
var rootCmd = &cobra.Command{
16-
Use: "ggit [<args>] <command>",
17-
Short: "ggit is a Git CLI that uses go-git as its backend.",
16+
Use: "gogit [<args>] <command>",
17+
Short: "gogit is a Git CLI that uses go-git as its backend.",
1818
RunE: func(cmd *cobra.Command, _ []string) error {
1919
return cmd.Usage()
2020
},

cmd/ggit/pull.go renamed to cmd/gogit/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"errors"
55

6-
"github.com/go-git/go-git/v5"
7-
"github.com/go-git/go-git/v5/plumbing/transport"
6+
"github.com/go-git/go-git/v6"
7+
"github.com/go-git/go-git/v6/plumbing/transport"
88
"github.com/spf13/cobra"
99
)
1010

cmd/ggit/push.go renamed to cmd/gogit/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package main
33
import (
44
"errors"
55

6-
"github.com/go-git/go-git/v5"
7-
"github.com/go-git/go-git/v5/config"
8-
"github.com/go-git/go-git/v5/plumbing/transport"
6+
"github.com/go-git/go-git/v6"
7+
"github.com/go-git/go-git/v6/config"
8+
"github.com/go-git/go-git/v6/plumbing/transport"
99
"github.com/spf13/cobra"
1010
"golang.org/x/term"
1111
)

cmd/gogit/receive-pack.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/go-git/go-git/v6"
7+
"github.com/go-git/go-git/v6/plumbing/transport"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var (
12+
receivePackStatelessRPC bool
13+
receivePackAdvertiseRefs bool
14+
)
15+
16+
func init() {
17+
receivePackCmd.Flags().BoolVarP(&receivePackStatelessRPC, "stateless-rpc", "", false, "Use stateless RPC")
18+
receivePackCmd.Flags().BoolVarP(&receivePackAdvertiseRefs, "advertise-refs", "", false, "Advertise refs")
19+
20+
rootCmd.AddCommand(receivePackCmd)
21+
}
22+
23+
var receivePackCmd = &cobra.Command{
24+
Use: "receive-pack <directory>",
25+
Short: "Run the receive-pack service",
26+
Args: cobra.ExactArgs(1),
27+
RunE: func(cmd *cobra.Command, args []string) error {
28+
r, err := git.PlainOpen(args[0])
29+
if err != nil {
30+
return err
31+
}
32+
33+
return transport.ReceivePack(
34+
cmd.Context(),
35+
r.Storer,
36+
os.Stdin,
37+
os.Stdout,
38+
&transport.ReceivePackOptions{
39+
GitProtocol: os.Getenv("GIT_PROTOCOL"),
40+
StatelessRPC: receivePackStatelessRPC,
41+
AdvertiseRefs: receivePackAdvertiseRefs,
42+
},
43+
)
44+
},
45+
}

cmd/gogit/update-server-info.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"github.com/go-git/go-git/v6"
5+
"github.com/go-git/go-git/v6/plumbing/transport"
6+
"github.com/go-git/go-git/v6/storage/filesystem"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func init() {
11+
rootCmd.AddCommand(updateServerInfoCmd)
12+
}
13+
14+
var updateServerInfoCmd = &cobra.Command{
15+
Use: "update-server-info",
16+
Short: "Update the server info file",
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
r, err := git.PlainOpen(".")
19+
if err != nil {
20+
return err
21+
}
22+
23+
fs := r.Storer.(*filesystem.Storage).Filesystem()
24+
return transport.UpdateServerInfo(r.Storer, fs)
25+
},
26+
}

cmd/gogit/upload-pack.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"os"
6+
"time"
7+
8+
"github.com/go-git/go-git/v6"
9+
"github.com/go-git/go-git/v6/plumbing/transport"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var (
14+
uploadPackStatelessRPC bool
15+
uploadPackAdvertiseRefs bool
16+
uploadPackTimeout int
17+
)
18+
19+
func init() {
20+
uploadPackCmd.Flags().BoolVarP(&uploadPackStatelessRPC, "stateless-rpc", "", false, "Use stateless RPC")
21+
uploadPackCmd.Flags().BoolVarP(&uploadPackAdvertiseRefs, "advertise-refs", "", false, "Advertise refs")
22+
uploadPackCmd.Flags().IntVarP(&uploadPackTimeout, "timeout", "", 0, "Timeout in seconds")
23+
24+
rootCmd.AddCommand(uploadPackCmd)
25+
}
26+
27+
var uploadPackCmd = &cobra.Command{
28+
Use: "upload-pack [options] <directory>",
29+
Short: "Run the upload-pack service",
30+
Args: cobra.ExactArgs(1),
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
r, err := git.PlainOpen(args[0])
33+
if err != nil {
34+
return err
35+
}
36+
37+
ctx := cmd.Context()
38+
if uploadPackTimeout > 0 {
39+
var cancel context.CancelFunc
40+
ctx, cancel = context.WithTimeout(ctx, time.Duration(uploadPackTimeout)*time.Second)
41+
defer cancel()
42+
}
43+
44+
return transport.UploadPack(
45+
ctx,
46+
r.Storer,
47+
os.Stdin,
48+
os.Stdout,
49+
&transport.UploadPackOptions{
50+
GitProtocol: os.Getenv("GIT_PROTOCOL"),
51+
StatelessRPC: uploadPackStatelessRPC,
52+
AdvertiseRefs: uploadPackAdvertiseRefs,
53+
},
54+
)
55+
},
56+
}

go.mod

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
module github.com/go-git/gogit
1+
module github.com/go-git/cli
22

3-
go 1.23.4
3+
go 1.23.0
44

55
require (
6-
github.com/go-git/go-git/v5 v5.13.0
6+
github.com/go-git/go-git/v6 v6.0.0-20250407095008-f3dca17d9094
77
github.com/spf13/cobra v1.8.1
8+
golang.org/x/crypto v0.36.0
9+
golang.org/x/term v0.30.0
810
)
911

1012
require (
1113
dario.cat/mergo v1.0.1 // indirect
1214
github.com/Microsoft/go-winio v0.6.2 // indirect
13-
github.com/ProtonMail/go-crypto v1.1.3 // indirect
14-
github.com/cloudflare/circl v1.5.0 // indirect
15-
github.com/cyphar/filepath-securejoin v0.3.5 // indirect
15+
github.com/ProtonMail/go-crypto v1.1.6 // indirect
16+
github.com/cloudflare/circl v1.6.0 // indirect
17+
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
1618
github.com/emirpasic/gods v1.18.1 // indirect
17-
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
19+
github.com/go-git/gcfg/v2 v2.0.1 // indirect
1820
github.com/go-git/go-billy/v5 v5.6.0 // indirect
1921
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
2022
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2123
github.com/kevinburke/ssh_config v1.2.0 // indirect
22-
github.com/pjbgf/sha1cd v0.3.0 // indirect
24+
github.com/pjbgf/sha1cd v0.3.2 // indirect
2325
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
2426
github.com/spf13/pflag v1.0.5 // indirect
25-
golang.org/x/crypto v0.31.0 // indirect
26-
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
27-
golang.org/x/net v0.33.0 // indirect
28-
golang.org/x/sys v0.28.0 // indirect
29-
gopkg.in/warnings.v0 v0.1.2 // indirect
27+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
28+
golang.org/x/net v0.37.0 // indirect
29+
golang.org/x/sys v0.31.0 // indirect
3030
)

0 commit comments

Comments
 (0)