Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Oct 9, 2023
1 parent 0731442 commit 7ecc307
Showing 1 changed file with 53 additions and 33 deletions.
86 changes: 53 additions & 33 deletions attest/vcs/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,29 @@ type (
}

GitObject struct {
TreeHash string `json:"treeHash,omitempty"`
CommitHash string `json:"commitHash,omitempty"`
Tags []string `json:"tags,omitempty"`
TreeHash string `json:"treeHash,omitempty"`
CommitHash string `json:"commitHash,omitempty"`
}

Signature struct {
PGP []byte `json:"pgp"`
Validated bool `json:"validated"`
}

GitTag struct {
Name string `json:"name"`
Hash string `json:"hash,omitempty"`
Target string `json:"target,omitempty"`
Signature *Signature `json:"signature,omitempty"`
}

GitReference struct {
Name string `json:"name,omitempty"`
Hash string `json:"hash,omitempty"`
Type string `json:"type,omitempty"`
Target string `json:"target,omitempty"`
Tags []string `json:"tags,omitempty"`
Name string `json:"name,omitempty"`
Hash string `json:"hash,omitempty"`
Type string `json:"type,omitempty"`
Target string `json:"target,omitempty"`
Tags []GitTag `json:"tags,omitempty"`
Signature *Signature `json:"signature,omitempty"`
}
)

Expand Down Expand Up @@ -151,9 +163,7 @@ func (c *PathChecker) MakeSummary() (types.PathCheckSummary, error) {

// TODO: determine position of local branch against remote
// TODO: introduce notion of primary remote branch to determine the possition of the working branch
// TODO: determine if a tag is used
// TODO: also check if local tag in sync wirth remote tag
// TODO: provide info on singed tags/commits

head, err := c.cache.repo.Head()
if err != nil {
Expand All @@ -179,6 +189,12 @@ func (c *PathChecker) MakeSummary() (types.PathCheckSummary, error) {
if err != nil {
return nil, err
}
if headCommit.PGPSignature != "" {
ref.Signature = &Signature{
PGP: []byte(headCommit.PGPSignature),
Validated: false,
}
}

if summary.Unmodified {
commitIter := object.NewCommitPathIterFromIter(
Expand All @@ -203,21 +219,6 @@ func (c *PathChecker) MakeSummary() (types.PathCheckSummary, error) {
obj.CommitHash = commit.Hash.String()
return nil

// //fmt.Println(commit.Hash, commit.TreeHash, obj.TreeHash)
// switch {
// case obj.Hash != "":
// return nil
// case c.IsTree():
// obj.Hash = commit.Hash.String()
// return nil
// case c.IsBlob():
// if commit.TreeHash.String() == obj.TreeHash {
// obj.Hash = commit.Hash.String()
// }
// return nil
// default:
// return nil
// }
}); err != nil {
return nil, err
}
Expand All @@ -230,19 +231,38 @@ func (c *PathChecker) MakeSummary() (types.PathCheckSummary, error) {
return nil, err
}

if err := tags.ForEach(func(tag *plumbing.Reference) error {
hash, err := c.cache.repo.ResolveRevision(plumbing.Revision(tag.Name()))
if err := tags.ForEach(func(t *plumbing.Reference) error {

target, err := c.cache.repo.ResolveRevision(plumbing.Revision(t.Name()))
if err != nil {
return err
}
h := hash.String()
t := tag.Name().Short()
if h == ref.Hash {
ref.Tags = append(ref.Tags, t)
if *target != head.Hash() {
// doesn't point to HEAD
return nil
}
if h == obj.CommitHash {
obj.Tags = append(obj.Tags, t)

tag := GitTag{
Name: t.Name().Short(),
Hash: t.Hash().String(),
Target: target.String(),
}

if tag.Target != tag.Hash {
// annotated tags have own object hash, while has of a leightweight tag is the same as target
tagObject, err := c.cache.repo.TagObject(t.Hash())
if err != nil {
return err
}
if tagObject.PGPSignature != "" {
tag.Signature = &Signature{
PGP: []byte(tagObject.PGPSignature),
Validated: false,
}
}
}

ref.Tags = append(ref.Tags, tag)
return nil
}); err != nil {
return nil, err
Expand Down

0 comments on commit 7ecc307

Please sign in to comment.