Skip to content

Commit bcf3029

Browse files
author
gitopia1c2zfrmhra3spfrc2m5ft64hef30guf60lvtcm3
committed
Merge pull request #12 from git-remote-gitopia/fix-lfsconfig
2 parents 2e16e2f + f1855bc commit bcf3029

File tree

8 files changed

+231
-124
lines changed

8 files changed

+231
-124
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes will be documented here.
44

5+
## [v1.7.0] - UNRELEASED
6+
7+
- Command to initialize lfs config
8+
- `git gitopia lfs init <remote_name>`
9+
- Performance improvements in fetch
10+
- Show progress in fetch and push
11+
512
## [v1.6.0] - 2023-06-07
613

714
- fix os keyring wallet in case of feegrant

cmd/git-gitopia/lfs/init.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package lfs
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io/fs"
7+
"os"
8+
"os/exec"
9+
"path"
10+
"strings"
11+
12+
"github.com/cosmos/cosmos-sdk/codec"
13+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
14+
"github.com/gitopia/git-remote-gitopia/config"
15+
"github.com/gitopia/git-remote-gitopia/core"
16+
gitopiatypes "github.com/gitopia/gitopia/v2/x/gitopia/types"
17+
"github.com/pkg/errors"
18+
"github.com/spf13/cobra"
19+
"google.golang.org/grpc"
20+
"google.golang.org/grpc/credentials/insecure"
21+
)
22+
23+
func InitCommand() *cobra.Command {
24+
cmd := &cobra.Command{
25+
Use: "init <remote_name>",
26+
Short: "Initialize the lfsconfig for the gitopia remote",
27+
Args: cobra.ExactArgs(1),
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
dir := path.Dir(os.Getenv("GIT_DIR"))
30+
if dir == "" {
31+
return errors.New("not a git repository")
32+
}
33+
34+
lfsConfigPath := path.Join(dir, ".lfsconfig")
35+
if _, err := os.Stat(lfsConfigPath); !errors.Is(err, fs.ErrNotExist) {
36+
return errors.New(".lfsconfig file already exists")
37+
38+
}
39+
40+
c := exec.Command("git", "remote", "get-url", args[0])
41+
output, err := c.Output()
42+
if err != nil {
43+
return errors.Wrap(err, "error reading the remote url")
44+
}
45+
46+
remoteURL := strings.TrimSpace(string(output))
47+
remoteUserId, remoteRepositoryName, err := core.ValidateGitopiaRemoteURL(string(remoteURL))
48+
if err != nil {
49+
return err
50+
}
51+
52+
interfaceRegistry := codectypes.NewInterfaceRegistry()
53+
54+
grpcConn, err := grpc.Dial(config.GRPCHost,
55+
grpc.WithTransportCredentials(insecure.NewCredentials()),
56+
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(interfaceRegistry).GRPCCodec())),
57+
)
58+
if err != nil {
59+
return err
60+
}
61+
defer grpcConn.Close()
62+
63+
queryClient := gitopiatypes.NewQueryClient(grpcConn)
64+
65+
// Get RepositoryId
66+
res, err := queryClient.AnyRepository(context.Background(), &gitopiatypes.QueryGetAnyRepositoryRequest{
67+
Id: remoteUserId,
68+
RepositoryName: remoteRepositoryName,
69+
})
70+
if err != nil {
71+
return err
72+
}
73+
74+
remoteRepository := *res.Repository
75+
lfsURL := fmt.Sprintf("%v/%v.git", config.GitServerHost, remoteRepository.Id)
76+
77+
c = core.GitCommand("git", "config",
78+
fmt.Sprintf("--file=%s", lfsConfigPath),
79+
"lfs.url",
80+
lfsURL)
81+
if err := c.Run(); err != nil {
82+
return errors.Wrap(err, "error creating .lfsconfig")
83+
}
84+
85+
return nil
86+
},
87+
}
88+
return cmd
89+
}

cmd/git-gitopia/lfs/root.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package lfs
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
func Commands() *cobra.Command {
8+
cmd := &cobra.Command{
9+
Use: "lfs",
10+
Short: "Configure the lfsconfig for the gitopia remote",
11+
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
12+
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
13+
},
14+
}
15+
cmd.AddCommand(InitCommand())
16+
17+
return cmd
18+
}

cmd/git-gitopia/main.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import (
66
"os"
77

88
"github.com/cosmos/cosmos-sdk/client"
9-
"github.com/cosmos/cosmos-sdk/client/keys"
10-
"github.com/cosmos/cosmos-sdk/codec"
11-
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
12-
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
13-
sdk "github.com/cosmos/cosmos-sdk/types"
149
"github.com/cosmos/cosmos-sdk/version"
15-
"github.com/spf13/cobra"
1610
)
1711

1812
const (
@@ -25,30 +19,8 @@ func main() {
2519
ctx := context.Background()
2620
ctx = context.WithValue(ctx, client.ClientContextKey, new(client.Context))
2721
version.Name = AppName // os keyring service name is same as version name
28-
cmd := &cobra.Command{
29-
Use: "gitopia",
30-
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
31-
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
32-
conf := sdk.GetConfig()
33-
conf.SetBech32PrefixForAccount(AccountAddressPrefix, AccountAddressPrefix+sdk.PrefixPublic)
34-
conf.Seal()
3522

36-
version.Name = AppName
37-
registry := codectypes.NewInterfaceRegistry()
38-
cryptocodec.RegisterInterfaces(registry)
39-
marshaler := codec.NewProtoCodec(registry)
40-
41-
initClientCtx := client.GetClientContextFromCmd(cmd).
42-
WithCodec(marshaler).
43-
WithInterfaceRegistry(registry).
44-
WithInput(os.Stdin)
45-
46-
// sets global flags for keys subcommand
47-
return client.SetCmdClientContextHandler(initClientCtx, cmd)
48-
},
49-
}
50-
cmd.AddCommand(keys.Commands("."))
51-
err := cmd.ExecuteContext(ctx)
23+
err := RootCommand().ExecuteContext(ctx)
5224
if err != nil {
5325
fmt.Fprint(os.Stderr, err.Error())
5426
return

cmd/git-gitopia/root.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/cosmos/cosmos-sdk/client"
7+
"github.com/cosmos/cosmos-sdk/client/keys"
8+
"github.com/cosmos/cosmos-sdk/codec"
9+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
10+
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
11+
sdk "github.com/cosmos/cosmos-sdk/types"
12+
"github.com/gitopia/git-remote-gitopia/cmd/git-gitopia/lfs"
13+
"github.com/spf13/cobra"
14+
)
15+
16+
func RootCommand() *cobra.Command {
17+
cmd := &cobra.Command{
18+
Use: "gitopia",
19+
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
20+
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
21+
conf := sdk.GetConfig()
22+
conf.SetBech32PrefixForAccount(AccountAddressPrefix, AccountAddressPrefix+sdk.PrefixPublic)
23+
conf.Seal()
24+
25+
registry := codectypes.NewInterfaceRegistry()
26+
cryptocodec.RegisterInterfaces(registry)
27+
marshaler := codec.NewProtoCodec(registry)
28+
29+
initClientCtx := client.GetClientContextFromCmd(cmd).
30+
WithCodec(marshaler).
31+
WithInterfaceRegistry(registry).
32+
WithInput(os.Stdin)
33+
34+
// sets global flags for keys subcommand
35+
return client.SetCmdClientContextHandler(initClientCtx, cmd)
36+
},
37+
}
38+
cmd.AddCommand(keys.Commands("."))
39+
cmd.AddCommand(lfs.Commands())
40+
41+
return cmd
42+
}

0 commit comments

Comments
 (0)