Skip to content

Commit

Permalink
Display upstream sha when git out of sync (#238)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaeljguarino authored Oct 25, 2022
1 parent ee58749 commit 3158c54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/plural/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
10 changes: 5 additions & 5 deletions pkg/utils/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand Down

0 comments on commit 3158c54

Please sign in to comment.