• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gittuf / gittuf / 13441148761

20 Feb 2025 05:29PM UTC coverage: 60.243% (+0.02%) from 60.219%
13441148761

push

github

web-flow
Merge pull request #843 from gittuf/gitinterface-object-type

gitinterface: Add GetObjectType

12 of 16 new or added lines in 1 file covered. (75.0%)

5943 of 9865 relevant lines covered (60.24%)

35.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/internal/gitinterface/object.go
1
// Copyright The gittuf Authors
2
// SPDX-License-Identifier: Apache-2.0
3

4
package gitinterface
5

6
import (
7
        "errors"
8
        "fmt"
9
)
10

11
type ObjectType uint
12

13
const (
14
        BlobObjectType ObjectType = iota + 1
15
        TreeObjectType
16
        CommitObjectType
17
        TagObjectType
18
)
19

20
var ErrInvalidObjectType = errors.New("unknown Git object type")
21

22
// HasObject returns true if an object with the specified Git ID exists in the
23
// repository.
24
func (r *Repository) HasObject(objectID Hash) bool {
30✔
25
        _, err := r.executor("cat-file", "-e", objectID.String()).executeString()
30✔
26
        return err == nil
30✔
27
}
30✔
28

29
func (r *Repository) GetObjectType(objectID Hash) (ObjectType, error) {
4✔
30
        objType, err := r.executor("cat-file", "-t", objectID.String()).executeString()
4✔
31
        if err != nil {
4✔
NEW
32
                return 0, fmt.Errorf("unable to inspect object type: %w", err)
×
NEW
33
        }
×
34

35
        switch objType {
4✔
36
        case "blob":
1✔
37
                return BlobObjectType, nil
1✔
38
        case "tree":
1✔
39
                return TreeObjectType, nil
1✔
40
        case "commit":
1✔
41
                return CommitObjectType, nil
1✔
42
        case "tag":
1✔
43
                return TagObjectType, nil
1✔
NEW
44
        default:
×
NEW
45
                return 0, ErrInvalidObjectType
×
46
        }
47
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc