diff options
Diffstat (limited to 'pkg/vcs')
| -rw-r--r-- | pkg/vcs/fuchsia.go | 4 | ||||
| -rw-r--r-- | pkg/vcs/git.go | 16 | ||||
| -rw-r--r-- | pkg/vcs/vcs.go | 3 |
3 files changed, 23 insertions, 0 deletions
diff --git a/pkg/vcs/fuchsia.go b/pkg/vcs/fuchsia.go index 223c0b860..2ad0e1878 100644 --- a/pkg/vcs/fuchsia.go +++ b/pkg/vcs/fuchsia.go @@ -103,3 +103,7 @@ func (ctx *fuchsia) Object(name, commit string) ([]byte, error) { func (ctx *fuchsia) MergeBases(firstCommit, secondCommit string) ([]*Commit, error) { return ctx.repo.MergeBases(firstCommit, secondCommit) } + +func (ctx *fuchsia) CommitExists(string) (bool, error) { + return false, fmt.Errorf("not implemented for fuchsia") +} diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index 840a8592e..d1a91404c 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -619,3 +619,19 @@ func (git *git) MergeBases(firstCommit, secondCommit string) ([]*Commit, error) } return ret, nil } + +// CommitExists relies on 'git cat-file -e'. +// If object exists its exit status is 0. +// If object doesn't exist its exit status is 1 (not documented). +// Otherwise, the exit status is 128 (not documented). +func (git *git) CommitExists(commit string) (bool, error) { + _, err := git.git("cat-file", "-e", commit) + var vErr *osutil.VerboseError + if errors.As(err, &vErr) && vErr.ExitCode == 1 { + return false, nil + } + if err != nil { + return false, err + } + return true, nil +} diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index faf1cf85d..0730ba721 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -69,6 +69,9 @@ type Repo interface { // MergeBases returns good common ancestors of the two commits. MergeBases(firstCommit, secondCommit string) ([]*Commit, error) + + // CommitExists check for the commit presence in local checkout. + CommitExists(commit string) (bool, error) } // Bisecter may be optionally implemented by Repo. |
