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

Commit 81d6577

Browse files
authored
Merge pull request #2 from MichaelMure/migration-2
Add keyring migration
2 parents 25114f9 + be2e5c5 commit 81d6577

File tree

245 files changed

+18381
-655
lines changed

Some content is hidden

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

245 files changed

+18381
-655
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.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ module github.com/MichaelMure/git-bug-migration
33
go 1.14
44

55
require (
6+
github.com/99designs/keyring v1.1.5
67
github.com/blang/semver v3.5.1+incompatible
78
github.com/dustin/go-humanize v1.0.0
89
github.com/fatih/color v1.9.0
10+
github.com/go-git/go-git/v5 v5.2.0
11+
github.com/mattn/go-isatty v0.0.12 // indirect
912
github.com/pkg/errors v0.9.1
1013
github.com/spf13/cobra v1.0.0
1114
github.com/stretchr/testify v1.6.1

0 commit comments

Comments
 (0)