Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 44ebefc

Browse files
authored
Merge pull request #3 from MichaelMure/improvements
plenty of structure improvements
2 parents 63a8977 + 40df7bf commit 44ebefc

File tree

191 files changed

+588
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+588
-465
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
matrix:
22
include:
3-
- language: go
4-
go: 1.12.x
53
- language: go
64
go: 1.13.x
75
- language: go
86
go: 1.14.x
7+
- language: go
8+
go: 1.15.x
99

1010
env:
1111
GO111MODULE=on

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GIT_COMMIT:=$(shell git rev-list -1 HEAD)
44
GIT_LAST_TAG:=$(shell git describe --abbrev=0 --tags)
55
GIT_EXACT_TAG:=$(shell git name-rev --name-only --tags HEAD)
66

7-
COMMANDS_PATH:=github.com/MichaelMure/git-bug-migration/commands
7+
COMMANDS_PATH:=main
88
LDFLAGS:=-X '${COMMANDS_PATH}.GitCommit=${GIT_COMMIT}' \
99
-X '${COMMANDS_PATH}.GitLastTag=${GIT_LAST_TAG}' \
1010
-X '${COMMANDS_PATH}.GitExactTag=${GIT_EXACT_TAG}'

commands/root.go

Lines changed: 0 additions & 106 deletions
This file was deleted.

env.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
stdpath "path"
8+
"path/filepath"
9+
10+
"github.com/pkg/errors"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// Env is the environment of a command
15+
type Env struct {
16+
out out
17+
err out
18+
19+
repoPath string
20+
}
21+
22+
func newEnv() *Env {
23+
return &Env{
24+
out: out{Writer: os.Stdout},
25+
err: out{Writer: os.Stderr},
26+
}
27+
}
28+
29+
type out struct {
30+
io.Writer
31+
}
32+
33+
func (o out) Printf(format string, a ...interface{}) {
34+
_, _ = fmt.Fprintf(o, format, a...)
35+
}
36+
37+
func (o out) Print(a ...interface{}) {
38+
_, _ = fmt.Fprint(o, a...)
39+
}
40+
41+
func (o out) Println(a ...interface{}) {
42+
_, _ = fmt.Fprintln(o, a...)
43+
}
44+
45+
// findRepo is a pre-run function that find the repository
46+
func findRepo(env *Env) func(*cobra.Command, []string) error {
47+
return func(cmd *cobra.Command, args []string) error {
48+
cwd, err := os.Getwd()
49+
if err != nil {
50+
return fmt.Errorf("unable to get the current working directory: %q", err)
51+
}
52+
53+
env.repoPath, err = detectGitPath(cwd)
54+
if err != nil {
55+
return errors.Wrap(err, "can't find the git repository")
56+
}
57+
58+
return nil
59+
}
60+
}
61+
62+
func detectGitPath(path string) (string, error) {
63+
// normalize the path
64+
path, err := filepath.Abs(path)
65+
if err != nil {
66+
return "", err
67+
}
68+
69+
for {
70+
fi, err := os.Stat(stdpath.Join(path, ".git"))
71+
if err == nil {
72+
if !fi.IsDir() {
73+
return "", fmt.Errorf(".git exist but is not a directory")
74+
}
75+
return stdpath.Join(path, ".git"), nil
76+
}
77+
if !os.IsNotExist(err) {
78+
// unknown error
79+
return "", err
80+
}
81+
82+
// detect bare repo
83+
ok, err := isGitDir(path)
84+
if err != nil {
85+
return "", err
86+
}
87+
if ok {
88+
return path, nil
89+
}
90+
91+
if parent := filepath.Dir(path); parent == path {
92+
return "", fmt.Errorf(".git not found")
93+
} else {
94+
path = parent
95+
}
96+
}
97+
}
98+
99+
func isGitDir(path string) (bool, error) {
100+
markers := []string{"HEAD", "objects", "refs"}
101+
102+
for _, marker := range markers {
103+
_, err := os.Stat(stdpath.Join(path, marker))
104+
if err == nil {
105+
continue
106+
}
107+
if !os.IsNotExist(err) {
108+
// unknown error
109+
return false, err
110+
} else {
111+
return false, nil
112+
}
113+
}
114+
115+
return true, nil
116+
}

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
5858
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
5959
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
6060
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
61+
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
6162
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
6263
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
6364
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
@@ -76,6 +77,7 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
7677
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
7778
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
7879
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
80+
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
7981
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
8082
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
8183
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=

main.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
package main
22

3-
import (
4-
"github.com/MichaelMure/git-bug-migration/commands"
5-
)
6-
7-
type Migration interface {
8-
Name() string
9-
Description() string
10-
NeedToRun() bool
11-
Run() error
12-
}
3+
import "os"
134

145
func main() {
15-
commands.Execute()
6+
if err := NewRootCommand().Execute(); err != nil {
7+
os.Exit(1)
8+
}
169
}

migration.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
type Migration interface {
4+
Description() string
5+
Run(repoPath string) error
6+
}
File renamed without changes.

migration01/after/bug/bug.go renamed to migration1/after/bug/bug.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88

99
"github.com/pkg/errors"
1010

11-
"github.com/MichaelMure/git-bug-migration/migration01/after/entity"
12-
"github.com/MichaelMure/git-bug-migration/migration01/after/identity"
13-
"github.com/MichaelMure/git-bug-migration/migration01/after/repository"
14-
"github.com/MichaelMure/git-bug-migration/migration01/after/util/git"
15-
"github.com/MichaelMure/git-bug-migration/migration01/after/util/lamport"
11+
"github.com/MichaelMure/git-bug-migration/migration1/after/entity"
12+
"github.com/MichaelMure/git-bug-migration/migration1/after/identity"
13+
"github.com/MichaelMure/git-bug-migration/migration1/after/repository"
14+
"github.com/MichaelMure/git-bug-migration/migration1/after/util/git"
15+
"github.com/MichaelMure/git-bug-migration/migration1/after/util/lamport"
1616
)
1717

1818
const bugsRefPattern = "refs/bugs/"

migration01/after/bug/bug_actions.go renamed to migration1/after/bug/bug_actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
"github.com/pkg/errors"
88

9-
"github.com/MichaelMure/git-bug-migration/migration01/after/entity"
10-
"github.com/MichaelMure/git-bug-migration/migration01/after/repository"
9+
"github.com/MichaelMure/git-bug-migration/migration1/after/entity"
10+
"github.com/MichaelMure/git-bug-migration/migration1/after/repository"
1111
)
1212

1313
// Fetch retrieve updates from a remote

0 commit comments

Comments
 (0)