From 3158c5497674d4674ef96df95220170b3fd4a68b Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Tue, 25 Oct 2022 03:25:16 -0400 Subject: [PATCH] Display upstream sha when git out of sync (#238) We currently still have a somewhat opaque error when you're local and remote repo is out-of-sync. Showing the expected sha should help a bit. --- cmd/plural/deploy.go | 4 ++-- pkg/utils/git/repo.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/plural/deploy.go b/cmd/plural/deploy.go index 6a4d3c7a..88fd07fa 100644 --- a/cmd/plural/deploy.go +++ b/cmd/plural/deploy.go @@ -99,14 +99,14 @@ func (p *Plural) build(c *cli.Context) error { if err := CheckGitCrypt(c); err != nil { return errors.ErrorWrap(errNoGit, "Failed to scan your repo for secrets to encrypt them") } - changed, err := git.HasUpstreamChanges() + changed, sha, err := git.HasUpstreamChanges() if err != nil { return errors.ErrorWrap(errNoGit, "Failed to get git information") } force := c.Bool("force") if !changed && !force { - return errors.ErrorWrap(errRemoteDiff, "Local Changes out of Sync") + return errors.ErrorWrap(errRemoteDiff, fmt.Sprintf("Expecting HEAD at commit=%s", sha)) } if c.IsSet("only") { diff --git a/pkg/utils/git/repo.go b/pkg/utils/git/repo.go index 7c81ccae..2ede823d 100644 --- a/pkg/utils/git/repo.go +++ b/pkg/utils/git/repo.go @@ -36,20 +36,20 @@ func CurrentBranch() (b string, err error) { return } -func HasUpstreamChanges() (bool, error) { +func HasUpstreamChanges() (bool, string, error) { repo, err := Repo() if err != nil { - return false, err + return false, "", err } ref, err := repo.Head() if err != nil { - return false, err + return false, "", err } res, err := GitRaw("ls-remote", "origin", "-h", fmt.Sprintf("refs/heads/%s", ref.Name().Short())) if err != nil { - return false, err + return false, "", err } scanner := bufio.NewScanner(strings.NewReader(res)) @@ -62,7 +62,7 @@ func HasUpstreamChanges() (bool, error) { } } - return remote == ref.Hash().String(), nil + return remote == ref.Hash().String(), remote, nil } func Init() (string, error) {