From 3ec76e5c6d6c0436939e91893d9756873fee526b Mon Sep 17 00:00:00 2001 From: Bret Walker Date: Tue, 18 Jul 2023 10:59:57 -0400 Subject: [PATCH] Print stderr when git fails (#15) --- cmd/get_targets.go | 4 ++-- internal/git_client.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/get_targets.go b/cmd/get_targets.go index 544695b..5b81853 100644 --- a/cmd/get_targets.go +++ b/cmd/get_targets.go @@ -60,8 +60,8 @@ $ bazel-differ get-targets -w path/to/workspace -b $(which bazel) -s START_HASH func getHashes(revision string, gitClient internal.GitClient, cacheManager cache.HashCacheManager, targetHasher internal.TargetHashingClient) map[string]string { - err := gitClient.Checkout(revision) - ExitIfError(err, fmt.Sprintf("Unable to checkout revision: %s", revision)) + output, err := gitClient.Checkout(revision) + ExitIfError(err, fmt.Sprintf("Unable to checkout revision: %s. %s", revision, output)) var seedfilePaths = make(map[string]bool) if SeedFilepaths != "" { diff --git a/internal/git_client.go b/internal/git_client.go index c98c2ea..a2adda9 100644 --- a/internal/git_client.go +++ b/internal/git_client.go @@ -5,7 +5,7 @@ import ( ) type GitClient interface { - Checkout(hash string) error + Checkout(hash string) (string, error) } type gitClient struct { @@ -18,8 +18,8 @@ func NewGitClient(dir string) GitClient { } } -func (g gitClient) Checkout(hash string) error { +func (g gitClient) Checkout(hash string) (string, error) { cmd := exec.Command("git", "-C", g.dir, "checkout", hash, "--quiet") - _, err := cmd.Output() - return err + output, err := cmd.CombinedOutput() + return string(output), err }