Skip to content

Commit 04417af

Browse files
committed
CV use git config --get
1 parent 0cc8914 commit 04417af

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

config/config.go

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,49 @@
11
package config
22

33
import (
4-
"cosmossdk.io/errors"
5-
goGitConfig "github.com/go-git/go-git/v5/config"
4+
"fmt"
5+
"os/exec"
6+
"strings"
67
)
78

89
const (
910
AppName = "git-remote-gitopia"
1011
gitopiaConfigSection = "gitopia"
11-
12-
gitopiaConfigChainid = "chainid"
13-
gitopiaConfigGrpchost = "grpchost"
14-
gitopiaConfigGitserverhost = "gitserverhost"
15-
gitopiaConfigTmaddr = "tmaddr"
16-
gitopiaConfigGasprices = "gasprices"
17-
gitopiaConfigFeegranter = "feegranter"
18-
gitopiaConfigDenom = "denom"
1912
)
2013

21-
func LoadGitConfig() error {
22-
conf, err := goGitConfig.LoadConfig(goGitConfig.GlobalScope)
14+
func gitConfigGet(key string) (string, error) {
15+
cmd := exec.Command("git", "config", "--get", fmt.Sprintf("gitopia.%s", key))
16+
stdout, err := cmd.Output()
17+
2318
if err != nil {
24-
return errors.Wrap(err, "error loading git config")
19+
return "", err
2520
}
26-
if conf.Raw.HasSection(gitopiaConfigSection) &&
27-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigChainid) {
28-
ChainId = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigChainid)
21+
22+
res := strings.TrimSpace(string(stdout))
23+
return res, nil
24+
}
25+
26+
func LoadGitConfig() error {
27+
if res, err := gitConfigGet("chainId"); err == nil {
28+
ChainId = res
2929
}
30-
if conf.Raw.HasSection(gitopiaConfigSection) &&
31-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGrpchost) {
32-
GRPCHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGrpchost)
30+
if res, err := gitConfigGet("grpcHost"); err == nil {
31+
GRPCHost = res
3332
}
34-
if conf.Raw.HasSection(gitopiaConfigSection) &&
35-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGitserverhost) {
36-
GitServerHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGitserverhost)
33+
if res, err := gitConfigGet("gitServerHost"); err == nil {
34+
GitServerHost = res
3735
}
38-
if conf.Raw.HasSection(gitopiaConfigSection) &&
39-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigTmaddr) {
40-
TmAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigTmaddr)
36+
if res, err := gitConfigGet("tmAddr"); err == nil {
37+
TmAddr = res
4138
}
42-
if conf.Raw.HasSection(gitopiaConfigSection) &&
43-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGasprices) {
44-
GasPrices = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGasprices)
39+
if res, err := gitConfigGet("gasPrices"); err == nil {
40+
GasPrices = res
4541
}
46-
if conf.Raw.HasSection(gitopiaConfigSection) &&
47-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigFeegranter) {
48-
FeeGranterAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigFeegranter)
42+
if res, err := gitConfigGet("feeGranter"); err == nil {
43+
FeeGranterAddr = res
4944
}
50-
if conf.Raw.HasSection(gitopiaConfigSection) &&
51-
conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigDenom) {
52-
Denom = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigDenom)
45+
if res, err := gitConfigGet("denom"); err == nil {
46+
Denom = res
5347
}
5448
return nil
5549
}

readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ For pushing git repositories to gitopia, you would require a gitopia wallet with
4949
export GITOPIA_WALLET=/path/to/wallet.json
5050
```
5151

52+
## Custom Endpoint Configuration Example
53+
54+
### Testnet
55+
```
56+
git config --global gitopia.chainId "gitopia"
57+
git config --global gitopia.grpcHost "localhost:9090"
58+
git config --global gitopia.gitServerhHst "http://localhost:5001"
59+
git config --global gitopia.tmAddr "http://localhost:26657"
60+
git config --global gitopia.gasPrices "0.001ulore"
61+
git config --global gitopia.feeGranter ""
62+
git config --global gitopia.denom "ulore"
63+
```
64+
65+
### Mainnet
66+
```
67+
git config --global gitopia.chainId "gitopia"
68+
git config --global gitopia.grpcHost "grpc.gitopia.com:9090"
69+
git config --global gitopia.gitServerHost "https://server.gitopia.com"
70+
git config --global gitopia.tmAddr "https://rpc.gitopia.com:443"
71+
git config --global gitopia.gasPrices "0.001ulore"
72+
git config --global gitopia.feeGranter "gitopia13ashgc6j5xle4m47kqyn5psavq0u3klmscfxql"
73+
git config --global gitopia.denom "ulore"
74+
```
75+
5276
## Troubleshooting
5377

5478
If you encounter the following error after installation, make sure to add `$GOBIN` to your `$PATH`

0 commit comments

Comments
 (0)