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.
48 lines
1.3 KiB
48 lines
1.3 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")
|
|
|
|
var proj proj
|
|
proj.initFlags(flag)
|
|
|
|
cmd.Run(func() (context.Context, error) {
|
|
if err := proj.openProj(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
commit, err := proj.GetCommitByRevision(plumbing.Revision(*rev))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("resolving revision %q: %w", *rev, err)
|
|
}
|
|
|
|
var branchName plumbing.ReferenceName
|
|
if *branch == "" {
|
|
if branchName, err = proj.ReferenceToBranchName(plumbing.HEAD); err != nil {
|
|
return nil, fmt.Errorf("determining branch at HEAD: %w", err)
|
|
}
|
|
} else {
|
|
branchName = plumbing.NewBranchReferenceName(*branch)
|
|
}
|
|
|
|
if err := proj.VerifyCommits(branchName, []dehub.Commit{commit}); err != nil {
|
|
return nil, fmt.Errorf("could not verify commit at %q (%s): %w",
|
|
*rev, commit.Hash, err)
|
|
}
|
|
|
|
fmt.Printf("commit at %q (%s) is good to go!\n", *rev, commit.Hash)
|
|
return nil, nil
|
|
})
|
|
}
|
|
|