Skip to content

Commit

Permalink
print git command to get changes
Browse files Browse the repository at this point in the history
  • Loading branch information
baruchiro committed Mar 18, 2024
1 parent a438cb2 commit 6402c9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ func runGit(folder string, commandAndArgs ...string) (string, error) {
return string(out), nil
}

var unpushedBranchesCommand = []string{"log", "--branches", "--not", "--remotes", `--pretty=format:"%h %d"`}

func (r *GitRepo) getUnpushedBranches() (map[string]string, error) {
out, err := runGit(r.folder, "log", "--branches", "--not", "--remotes", `--pretty=format:"%h %d"`)
out, err := runGit(r.folder, unpushedBranchesCommand...)
if err != nil {
return nil, fmt.Errorf("error running git log: %w", err)
}
Expand All @@ -50,8 +52,10 @@ func (r *GitRepo) getUnpushedBranches() (map[string]string, error) {
return branches, nil
}

var unpushedChangesCommand = []string{"status", "--porcelain"}

func (r *GitRepo) getUnpushedChanges() (int, error) {
out, err := runGit(r.folder, "status", "--porcelain")
out, err := runGit(r.folder, unpushedChangesCommand...)
if err != nil {
return -1, fmt.Errorf("error running git status: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"text/tabwriter"

Expand Down Expand Up @@ -120,6 +121,9 @@ func main() {
}
}
w.Flush()

log.Info("To see the unpushed branches, run: git " + strings.Join(unpushedBranchesCommand, " "))
log.Info("To see the unpushed changes, run: git " + strings.Join(unpushedChangesCommand, " "))
}

// For more examples of using go-gh, see:
Expand Down

0 comments on commit 6402c9f

Please sign in to comment.