A read-only clone of the dehub project, for until dehub.dev can be brought back online.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
dehub/cmd/dehub/cmd_verify.go

44 lines
1.2 KiB

package main
import (
"context"
"fmt"
"dehub.dev/src/dehub.git"
"dehub.dev/src/dehub.git/cmd/dehub/dcmd"
"gopkg.in/src-d/go-git.v4/plumbing"
)
func cmdVerify(ctx context.Context, cmd *dcmd.Cmd) {
flag := cmd.FlagSet()
rev := flag.String("rev", "HEAD", "Revision of commit to verify")
branch := flag.String("branch", "", "Branch that the revision is on. If not given then the currently checked out branch is assumed")
cmd.Run(func() (context.Context, error) {
repo := ctxRepo(ctx)
gitCommit, err := repo.GetGitRevision(plumbing.Revision(*rev))
if err != nil {
return nil, fmt.Errorf("resolving revision %q: %w", *rev, err)
}
gitCommitHash := gitCommit.GitCommit.Hash
var branchName plumbing.ReferenceName
if *branch == "" {
if branchName, err = repo.ReferenceToBranchName(plumbing.HEAD); err != nil {
return nil, fmt.Errorf("determining branch at HEAD: %w", err)
}
} else {
branchName = plumbing.NewBranchReferenceName(*branch)
}
if err := repo.VerifyCommits(branchName, []dehub.GitCommit{gitCommit}); err != nil {
return nil, fmt.Errorf("could not verify commit at %q (%s): %w",
*rev, gitCommitHash, err)
}
fmt.Printf("commit at %q (%s) is good to go!\n", *rev, gitCommitHash)
return nil, nil
})
}