Skip to content

Commit 834e954

Browse files
committed
Clean up
1 parent 5c5f0d2 commit 834e954

File tree

6 files changed

+1319
-69
lines changed

6 files changed

+1319
-69
lines changed

cmd/git-backup/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ func loadConfig() gitbackup.Config {
5050
os.Exit(1)
5151
}
5252
return config
53-
}
53+
}

config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ type Config struct {
1313
func (c *Config) GetSources() []RepositorySource {
1414
sources := make([]RepositorySource, len(c.Github))
1515

16-
offset := 0;
16+
offset := 0
1717
for i := 0; i < len(c.Github); i++ {
18-
sources[i + offset] = c.Github[i]
18+
sources[i+offset] = c.Github[i]
1919
offset++
2020
}
2121

@@ -30,7 +30,6 @@ func (c *Config) setDefaults() {
3030
}
3131
}
3232

33-
3433
func LoadFile(path string) (out Config, err error) {
3534
handle, err := os.Open(path)
3635
if err != nil {
@@ -49,4 +48,4 @@ func LoadReader(reader io.Reader) (out Config, err error) {
4948
err = dec.Decode(&out)
5049
out.setDefaults()
5150
return
52-
}
51+
}

github.go

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ package git_backup
33
import (
44
"context"
55
"fmt"
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/v5/plumbing/transport/http"
96
"github.com/google/go-github/v43/github"
107
"golang.org/x/oauth2"
8+
"log"
119
"net/url"
12-
"os"
1310
)
1411

1512
type GithubConfig struct {
@@ -24,7 +21,7 @@ func (c *GithubConfig) Test() error {
2421
if err != nil {
2522
return err
2623
}
27-
fmt.Printf("Authenticated with github as: %s", me.Login)
24+
log.Printf("Authenticated with github as: %s", *me.Login)
2825
return nil
2926
}
3027

@@ -44,7 +41,10 @@ func (c *GithubConfig) ListRepositories() ([]*Repository, error) {
4441
return out, err
4542
}
4643
gitUrl.User = url.UserPassword("github", c.AccessToken)
47-
out[i] = &Repository{GitURL: *gitUrl}
44+
out[i] = &Repository{
45+
FullName: *repo.FullName,
46+
GitURL: *gitUrl,
47+
}
4848
}
4949
return out, nil
5050
}
@@ -130,50 +130,3 @@ func (c *GithubConfig) getStarredRepos(page int) ([]*github.Repository, *github.
130130
}
131131
return repos, response, err
132132
}
133-
134-
func (c *GithubConfig) CloneInto(repo *github.Repository, path string) error {
135-
auth := &http.BasicAuth{
136-
Username: "git",
137-
Password: c.AccessToken,
138-
}
139-
gitRepo, err := git.PlainClone(path, false, &git.CloneOptions{
140-
URL: *repo.CloneURL,
141-
Auth: auth,
142-
Progress: os.Stdout,
143-
})
144-
switch err {
145-
case transport.ErrEmptyRemoteRepository:
146-
return nil
147-
default:
148-
return err
149-
case git.ErrRepositoryAlreadyExists:
150-
fallthrough
151-
case nil:
152-
}
153-
if err == git.ErrRepositoryAlreadyExists {
154-
if gitRepo, err = git.PlainOpen(path); err != nil {
155-
return err
156-
} else if w, err := gitRepo.Worktree(); err != nil {
157-
return err
158-
} else if err := w.Pull(&git.PullOptions{
159-
Auth: auth,
160-
Progress: os.Stdout,
161-
}); err == git.NoErrAlreadyUpToDate {
162-
return nil
163-
} else if err != nil {
164-
return err
165-
}
166-
}
167-
err = gitRepo.Fetch(&git.FetchOptions{
168-
Auth: auth,
169-
Progress: os.Stdout,
170-
Tags: git.AllTags,
171-
Force: true,
172-
})
173-
switch err {
174-
case git.NoErrAlreadyUpToDate:
175-
return nil
176-
default:
177-
return err
178-
}
179-
}

go.mod

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,61 @@ module git-backup
33
go 1.17
44

55
require (
6+
github.com/ChappIO/terraform-encrypt v0.0.0-20190529081821-8d96f6eb70d9
67
github.com/go-git/go-git/v5 v5.4.2
78
github.com/google/go-github/v43 v43.0.0
8-
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
9+
github.com/gorilla/pat v1.0.1
10+
github.com/ian-kent/envconf v0.0.0-20141026121121-c19809918c02
11+
github.com/ian-kent/go-log v0.0.0-20160113211217-5731446c36ab
12+
github.com/influxdata/influxdb v1.9.6
13+
github.com/karalabe/hid v1.0.0
14+
github.com/mailhog/MailHog v1.0.1
15+
github.com/mailhog/MailHog-Server v1.0.1
16+
github.com/mailhog/MailHog-UI v1.0.1
17+
github.com/mailhog/http v1.0.1
18+
github.com/mailhog/mhsendmail v0.2.0
19+
github.com/spf13/cobra v1.4.0
20+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
21+
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
922
gopkg.in/yaml.v2 v2.4.0
1023
)
1124

1225
require (
1326
github.com/Microsoft/go-winio v0.4.16 // indirect
1427
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
1528
github.com/acomagu/bufpipe v1.0.3 // indirect
29+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
1630
github.com/emirpasic/gods v1.12.0 // indirect
1731
github.com/go-git/gcfg v1.5.0 // indirect
1832
github.com/go-git/go-billy/v5 v5.3.1 // indirect
19-
github.com/golang/protobuf v1.3.2 // indirect
33+
github.com/golang/protobuf v1.5.2 // indirect
2034
github.com/google/go-querystring v1.1.0 // indirect
35+
github.com/gorilla/context v1.1.1 // indirect
36+
github.com/gorilla/mux v1.8.0 // indirect
37+
github.com/gorilla/websocket v1.5.0 // indirect
38+
github.com/ian-kent/goose v0.0.0-20141221090059-c3541ea826ad // indirect
39+
github.com/ian-kent/linkio v0.0.0-20170807205755-97566b872887 // indirect
2140
github.com/imdario/mergo v0.3.12 // indirect
41+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2242
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
2343
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
44+
github.com/mailhog/data v1.0.1 // indirect
45+
github.com/mailhog/smtp v1.0.1 // indirect
46+
github.com/mailhog/storage v1.0.1 // indirect
2447
github.com/mitchellh/go-homedir v1.1.0 // indirect
48+
github.com/ogier/pflag v0.0.1 // indirect
49+
github.com/philhofer/fwd v1.0.0 // indirect
2550
github.com/sergi/go-diff v1.1.0 // indirect
51+
github.com/smartystreets/goconvey v1.7.2 // indirect
52+
github.com/spf13/pflag v1.0.5 // indirect
53+
github.com/t-k/fluent-logger-golang v1.0.0 // indirect
54+
github.com/tinylib/msgp v1.1.0 // indirect
2655
github.com/xanzy/ssh-agent v0.3.0 // indirect
27-
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
28-
golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect
29-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
56+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
57+
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
58+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
3059
google.golang.org/appengine v1.6.7 // indirect
60+
google.golang.org/protobuf v1.27.1 // indirect
61+
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
3162
gopkg.in/warnings.v0 v0.1.2 // indirect
3263
)

0 commit comments

Comments
 (0)