From 9c1ba22ff198757751c81af3a91ba279c86b83b8 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 29 Dec 2019 17:17:38 +0800 Subject: [PATCH] fix: fix git format issue --- cmd/git.go | 5 ++--- core/domain/todo/todo_app.go | 4 ++-- core/support/file_analysis_helper.go | 2 +- core/support/file_helper.go | 12 ++++++------ 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/git.go b/cmd/git.go index e98913e..8c66cb9 100644 --- a/cmd/git.go +++ b/cmd/git.go @@ -115,17 +115,16 @@ var gitCmd = &cobra.Command{ } GetRelatedFiles(commitMessages, config) - //results := GetRelatedFiles(commitMessages, config) - //fmt.Println(results) } }, } func getCommitMessage() string { - historyArgs := []string{"log", "--pretty=format:[%h] %aN %ad %s", "--date=short", "--numstat", "--reverse", "--summary"} + historyArgs := []string{"log", "--pretty=\"format:[%h] %aN %ad %s\"", "--date=short", "--numstat", "--reverse", "--summary"} cmd := exec.Command("git", historyArgs...) out, err := cmd.CombinedOutput() if err != nil { + fmt.Println(string(out)) log.Fatalf("cmd.Run() failed with %s\n", err) } diff --git a/core/domain/todo/todo_app.go b/core/domain/todo/todo_app.go index c54b41c..35e38fd 100644 --- a/core/domain/todo/todo_app.go +++ b/core/domain/todo/todo_app.go @@ -95,11 +95,11 @@ func buildComment(path string) []*astitodo.TODO { func runGitGetLog(line int, fileName string) string { // git log -1 -L2:README.md --pretty="format:[%h] %aN %ad %s" --date=short --numstat - historyArgs := []string{"log", "-1", "-L" + strconv.Itoa(line) + ":" + fileName, "--pretty=format:[%h] %aN %ad %s", "--date=short", "--numstat", "--summary"} + historyArgs := []string{"log", "-1", "-L" + strconv.Itoa(line) + ":" + fileName, "--pretty=\"format:[%h] %aN %ad %s\"", "--date=short", "--numstat", "--summary"} cmd := exec.Command("git", historyArgs...) out, err := cmd.CombinedOutput() if err != nil { - fmt.Println(out) + fmt.Println(string(out)) log.Fatalf("cmd.Run() failed with %s\n", err) } diff --git a/core/support/file_analysis_helper.go b/core/support/file_analysis_helper.go index 2be4db9..4797559 100644 --- a/core/support/file_analysis_helper.go +++ b/core/support/file_analysis_helper.go @@ -14,7 +14,7 @@ func GetJavaFiles(codeDir string) []string { files := make([]string, 0) gitIgnore, err := ignore.CompileIgnoreFile(".gitignore") if err != nil { - fmt.Println(err) + //fmt.Println(err) } fi, err := os.Stat(codeDir) diff --git a/core/support/file_helper.go b/core/support/file_helper.go index 3674ecf..1cb74d4 100644 --- a/core/support/file_helper.go +++ b/core/support/file_helper.go @@ -5,23 +5,23 @@ import ( "github.com/phodal/coca/config" "io/ioutil" "os" + "path/filepath" ) var reporterPath = config.CocaConfig.ReporterPath func WriteToCocaFile(fileName string, payload string) { if _, err := os.Stat(reporterPath); os.IsNotExist(err) { - - err := os.Mkdir(reporterPath, os.ModePerm) - if err != nil { - fmt.Println(err) + mkdirErr := os.Mkdir(reporterPath, os.ModePerm) + if mkdirErr != nil { + fmt.Println(mkdirErr) } } - _ = ioutil.WriteFile(reporterPath+"/"+fileName, []byte(payload), os.ModePerm) + _ = ioutil.WriteFile(filepath.FromSlash(reporterPath+"/"+fileName), []byte(payload), os.ModePerm) } func ReadCocaFile(fileName string) []byte { - return ReadFile(reporterPath + "/" + fileName) + return ReadFile(filepath.FromSlash(reporterPath + "/" + fileName)) } func ReadFile(fileName string) []byte { -- GitLab