Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/clienter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Clienter interface {
GetLogins(ctx context.Context) ([]string, error)
GetRepos(ctx context.Context, name string) ([]*github.Repository, error)
ListTags(ctx context.Context, repoDirs []string, args ...string) error
LogRepos(ctx context.Context, repoDirs []string, ignoreEmtpy bool, args ...string) error
PullRepos(ctx context.Context, repoDirs []string, args ...string) error
PushRepos(ctx context.Context, repoDirs []string, args ...string) error
Remotes(ctx context.Context, repoDirs []string, args ...string) error
Expand Down
49 changes: 49 additions & 0 deletions client/repos_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package client

import (
"bytes"
"context"
"fmt"
"os/exec"
"strings"
)

func (c *Client) LogRepos(ctx context.Context, dirs []string, ignoreEmpty bool, args ...string) error {
args = append([]string{"log"}, args...)

c.scrb.BeginDescribe("Command")
defer c.scrb.EndDescribe()

c.scrb.Print(fmt.Sprintf("git %s", strings.Join(args, " ")))

c.scrb.BeginDescribe("directories")
defer c.scrb.EndDescribe()

for _, dir := range dirs {
out := &bytes.Buffer{}
errout := &bytes.Buffer{}

cmd := exec.CommandContext(ctx, "git", args...)
cmd.Stdout = out
cmd.Stderr = errout
cmd.Dir = dir

err := cmd.Run()

if ignoreEmpty && out.Len() == 0 && err == nil {
continue
}

c.scrb.BeginDescribe(dir)
if err != nil {
c.scrb.Error(err)
c.scrb.PrintLines(errout)
} else {
c.scrb.PrintLines(out)
}

c.scrb.EndDescribe()
}

return nil
}
6 changes: 6 additions & 0 deletions client/testclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ func (c *TestClient) DiffRepos(ctx context.Context, repoDirs []string, cfg *clie

return nil
}

func (c *TestClient) LogRepos(ctx context.Context, repoDirs []string, ignoreEmtpy bool, args ...string) error {
c.CommandsCalled = append(c.CommandsCalled, "LogRepos")

return nil
}
56 changes: 56 additions & 0 deletions cmd/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import (
"context"
"fmt"

"github.com/spf13/cobra"
)

var (
oneline bool
noColor bool
)

func init() {
RootCmd.AddCommand(logCmd)

logCmd.Flags().BoolVar(&oneline, "oneline", false, "Show each commit on a single line")
logCmd.Flags().BoolVar(&noColor, "no-color", false, "Disable color output")
logCmd.Flags().BoolVar(&ignoreEmtpy, "ignore-empty", false, "Ignore empty repositories")
}

var logCmd = &cobra.Command{
Use: "log",
Short: "Show commit logs for all repos in a directory",
Long: `Show commit logs all repos in a directory. Since commit hashes would not be the same between
multiple repos this command really only makes sense when used with two branch names or two tags.`,
PersistentPreRun: setupClient,
RunE: logFunc,
}

func logFunc(cmd *cobra.Command, args []string) error {
ctx := context.Background()

repoDirs, err := clt.GetDirs(ctx, dir)
if err != nil {
cmd.SilenceUsage = true
return fmt.Errorf("get dirs: %w", err)
}

if oneline {
args = append(args, "--oneline")
}

if !noColor {
args = append(args, "--color")
}

err = clt.LogRepos(ctx, repoDirs, ignoreEmtpy, args...)
if err != nil {
cmd.SilenceUsage = true
return fmt.Errorf("log repos: %w", err)
}

return nil
}
Loading