Skip to content

Commit 3158c54

Browse files
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.
1 parent ee58749 commit 3158c54

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

cmd/plural/deploy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ func (p *Plural) build(c *cli.Context) error {
9999
if err := CheckGitCrypt(c); err != nil {
100100
return errors.ErrorWrap(errNoGit, "Failed to scan your repo for secrets to encrypt them")
101101
}
102-
changed, err := git.HasUpstreamChanges()
102+
changed, sha, err := git.HasUpstreamChanges()
103103
if err != nil {
104104
return errors.ErrorWrap(errNoGit, "Failed to get git information")
105105
}
106106

107107
force := c.Bool("force")
108108
if !changed && !force {
109-
return errors.ErrorWrap(errRemoteDiff, "Local Changes out of Sync")
109+
return errors.ErrorWrap(errRemoteDiff, fmt.Sprintf("Expecting HEAD at commit=%s", sha))
110110
}
111111

112112
if c.IsSet("only") {

pkg/utils/git/repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ func CurrentBranch() (b string, err error) {
3636
return
3737
}
3838

39-
func HasUpstreamChanges() (bool, error) {
39+
func HasUpstreamChanges() (bool, string, error) {
4040
repo, err := Repo()
4141
if err != nil {
42-
return false, err
42+
return false, "", err
4343
}
4444

4545
ref, err := repo.Head()
4646
if err != nil {
47-
return false, err
47+
return false, "", err
4848
}
4949

5050
res, err := GitRaw("ls-remote", "origin", "-h", fmt.Sprintf("refs/heads/%s", ref.Name().Short()))
5151
if err != nil {
52-
return false, err
52+
return false, "", err
5353
}
5454

5555
scanner := bufio.NewScanner(strings.NewReader(res))
@@ -62,7 +62,7 @@ func HasUpstreamChanges() (bool, error) {
6262
}
6363
}
6464

65-
return remote == ref.Hash().String(), nil
65+
return remote == ref.Hash().String(), remote, nil
6666
}
6767

6868
func Init() (string, error) {

0 commit comments

Comments
 (0)