Skip to content

Commit

Permalink
fix: show multiple commits correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed May 11, 2017
1 parent f7bba9c commit 0b1b500
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions command_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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()
Expand Down
16 changes: 9 additions & 7 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0b1b500

Please sign in to comment.