From 0b1b50093d62e17d628b3b609b56503da80aa059 Mon Sep 17 00:00:00 2001 From: Yasuaki Uechi Date: Thu, 11 May 2017 15:04:06 +0900 Subject: [PATCH] fix: show multiple commits correctly --- command_list.go | 14 ++++++++------ git.go | 16 +++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/command_list.go b/command_list.go index 0a1f377..389e8eb 100644 --- a/command_list.go +++ b/command_list.go @@ -52,8 +52,8 @@ func doList(c *cli.Context) error { // print uncommited changes if ccErr == nil { - printlnWithColor("[Uncommitted Changes]", ct.Magenta) - for _, changes := range uncommitedChanges[:len(uncommitedChanges)-1] { + printlnWithColor("uncommitted changes", ct.Magenta) + for _, changes := range uncommitedChanges { staged := changes[:1] unstaged := changes[1:2] filename := changes[3:] @@ -70,10 +70,12 @@ func doList(c *cli.Context) error { // print unpushed commits if pcErr == nil { - printlnWithColor("[Unpushed Commits]", ct.Magenta) - line := strings.Split(unpushedCommits, " ") - printWithColor(line[0], ct.Yellow) - fmt.Print(" " + strings.Join(line[1:], " ")) + printlnWithColor("unpushed commits", ct.Magenta) + for _, commit := range unpushedCommits { + line := strings.Split(commit, " ") + printWithColor(line[0], ct.Yellow) + fmt.Println(" " + strings.Join(line[1:], " ")) + } } fmt.Println() diff --git a/git.go b/git.go index 374df9c..f7ad8ed 100644 --- a/git.go +++ b/git.go @@ -79,32 +79,34 @@ func GitStatus(targetPath string) ([]string, error) { return nil, errors.New("No status changed") } - statuses := strings.Split(string(out), "\n") + statuses := strings.Split(strings.TrimSpace(string(out)), "\n") return statuses, nil } // git log --branches --not --remotes -func GitLog(targetPath string) (string, error) { +func GitLog(targetPath string) ([]string, error) { if err := os.Chdir(targetPath); err != nil { - return "", err + return nil, err } out, err := exec.Command("git", "log", "--branches", "--not", "--remotes", "--oneline").CombinedOutput() if err != nil { eout := string(out) if strings.HasPrefix(eout, "does not have any commits yet") { - return "", &NoCommitsError{targetPath} + return nil, &NoCommitsError{targetPath} } else { - return "", err + return nil, err } } if len(out) == 0 { - return "", errors.New("No output") + return nil, errors.New("No output") } - return string(out), nil + statuses := strings.Split(strings.TrimSpace(string(out)), "\n") + + return statuses, nil } func GitRemoteAdd(targetPath string, name string, url string) error {