Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Do not fail with bad revision on missing sync tag
Browse files Browse the repository at this point in the history
But instead fallback to comparison on an empty revision string as
current revision as this does no harm.
  • Loading branch information
hiddeco committed Mar 25, 2019
1 parent 82a1957 commit c823567
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 8 additions & 2 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (d *Daemon) sync() jobFunc {
return result, err
}
syncHead, err := d.Repo.Revision(ctx, d.GitConfig.SyncTag)
if err != nil {
if err != nil && !isUnknownRevision(err) {
return result, err
}
var latestVerifiedRev string
Expand Down Expand Up @@ -805,7 +805,7 @@ func latestValidRevision(ctx context.Context, repo *git.Repo, gitConfig git.Conf
}

func verifyWorkingRepo(ctx context.Context, repo *git.Repo, working *git.Checkout, gitConfig git.Config) error {
if syncRevision, err := working.SyncRevision(ctx); err != nil {
if syncRevision, err := working.SyncRevision(ctx); err != nil && !isUnknownRevision(err) {
return err
} else if latestVerifiedRev, _, err := latestValidRevision(ctx, repo, gitConfig, syncRevision); err != nil {
return err
Expand All @@ -819,3 +819,9 @@ The last verified commit was %.8s. HEAD is %.8s.`, latestVerifiedRev, headRev)
}
return nil
}

func isUnknownRevision(err error) bool {
return err != nil &&
(strings.Contains(err.Error(), "unknown revision or path not in the working tree.") ||
strings.Contains(err.Error(), "bad revision"))
}
7 changes: 0 additions & 7 deletions daemon/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"github.com/go-kit/kit/log"
"github.com/pkg/errors"
"strings"
"time"

"github.com/weaveworks/flux"
Expand Down Expand Up @@ -388,12 +387,6 @@ func refresh(ctx context.Context, s *Sync) error {
return err
}

func isUnknownRevision(err error) bool {
return err != nil &&
(strings.Contains(err.Error(), "unknown revision or path not in the working tree.") ||
strings.Contains(err.Error(), "bad revision"))
}

func makeGitConfigHash(remote git.Remote, conf git.Config) string {
urlbit := remote.SafeURL()
pathshash := sha256.New()
Expand Down

0 comments on commit c823567

Please sign in to comment.