Skip to content

Commit

Permalink
feat: remove import integralist/go-findroot
Browse files Browse the repository at this point in the history
  • Loading branch information
tingzhen.lin committed Dec 23, 2022
1 parent ce90b3d commit 1a7412e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
11 changes: 5 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"

"github.com/integralist/go-findroot/find"
"github.com/lintingzhen/commitizen-go/commit"
"github.com/lintingzhen/commitizen-go/git"
homedir "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -59,14 +58,14 @@ func initConfig() {
log.Printf("Get home dir failed, err=%v\n", err)
os.Exit(1)
}
stat, err := find.Repo()
if err != nil {
log.Printf("Get git repository root failed, err=%v\n", err)
workingTreeRoot, err := git.WorkingTreeRoot()
if err != nil || workingTreeRoot == "" {
log.Printf("current directory is not a git working tree\n")
os.Exit(1)
}

// Search config in home directory and repository root directory with name ".git-czrc" or ".git-czrc.json".
viper.AddConfigPath(stat.Path)
// Search config in repository working tree root directory and home directory with name ".git-czrc" or ".git-czrc.json".
viper.AddConfigPath(workingTreeRoot)
viper.AddConfigPath(home)
viper.SetConfigName(".git-czrc")
viper.SetConfigType("json")
Expand Down
9 changes: 9 additions & 0 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func IsCurrentDirectoryGitRepo() (bool, error) {
return true, nil
}

// WorkingTreeRoot return path of the top-level directory of the working tree
func WorkingTreeRoot() (path string, err error) {
output, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(output)), nil
}

func CommitMessage(message []byte, all bool) ([]byte, error) {
// save the commit message to temp file
var err error
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.16
require (
github.com/AlecAivazis/survey/v2 v2.3.2
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.3
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDG
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc h1:4IZpk3M4m6ypx0IlRoEyEyY1gAdicWLMQ0NcG/gBnnA=
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc/go.mod h1:UlaC6ndby46IJz9m/03cZPKKkR9ykeIVBBDE3UDBdJk=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand Down

0 comments on commit 1a7412e

Please sign in to comment.