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

gittuf / gittuf / 29552153989

17 Jul 2026 03:20AM UTC coverage: 78.033% (+0.2%) from 77.791%
29552153989

push

github

web-flow
Merge pull request #1472 from pjbgf/sha256

feat(sha256): support SHA-256 object format

179 of 220 new or added lines in 11 files covered. (81.36%)

2 existing lines in 2 files now uncovered.

12721 of 16302 relevant lines covered (78.03%)

36.22 hits per line

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

95.79
/pkg/gitinterface/sync.go
1
// Copyright The gittuf Authors
2
// SPDX-License-Identifier: Apache-2.0
3

4
package gitinterface
5

6
import (
7
        "fmt"
8
        "path"
9
        "strings"
10

11
        "github.com/jonboulle/clockwork"
12
)
13

14
const DefaultRemoteName = "origin"
15

16
type FetchOptions struct {
17
        Depth int
18
}
19

20
type FetchOption func(*FetchOptions)
21

22
func WithFetchDepth(depth int) FetchOption {
2✔
23
        return func(o *FetchOptions) {
4✔
24
                o.Depth = depth
2✔
25
        }
2✔
26
}
27

28
func (r *Repository) PushRefSpec(remoteName string, refSpecs []string) error {
11✔
29
        args := []string{"push", remoteName}
11✔
30
        args = append(args, refSpecs...)
11✔
31

11✔
32
        _, err := r.executor(args...).executeString()
11✔
33
        if err != nil {
13✔
34
                return fmt.Errorf("unable to push: %w", err)
2✔
35
        }
2✔
36

37
        return nil
9✔
38
}
39

40
func (r *Repository) Push(remoteName string, refs []string) error {
7✔
41
        refSpecs := make([]string, 0, len(refs))
7✔
42
        for _, ref := range refs {
14✔
43
                refSpec, err := r.RefSpec(ref, "", true)
7✔
44
                if err != nil {
8✔
45
                        return err
1✔
46
                }
1✔
47
                refSpecs = append(refSpecs, refSpec)
6✔
48
        }
49

50
        return r.PushRefSpec(remoteName, refSpecs)
6✔
51
}
52

53
func (r *Repository) FetchRefSpec(remoteName string, refSpecs []string, opts ...FetchOption) error {
19✔
54
        options := &FetchOptions{}
19✔
55
        for _, fn := range opts {
20✔
56
                fn(options)
1✔
57
        }
1✔
58

59
        args := []string{"fetch"}
19✔
60

19✔
61
        if options.Depth != 0 {
20✔
62
                args = append(args, "--depth", fmt.Sprintf("%d", options.Depth))
1✔
63
        }
1✔
64

65
        args = append(args, remoteName)
19✔
66
        args = append(args, refSpecs...)
19✔
67

19✔
68
        _, err := r.executor(args...).executeString()
19✔
69
        if err != nil {
21✔
70
                return fmt.Errorf("unable to fetch: %w", err)
2✔
71
        }
2✔
72

73
        return nil
17✔
74
}
75

76
func (r *Repository) Fetch(remoteName string, refs []string, fastForwardOnly bool, opts ...FetchOption) error {
14✔
77
        refSpecs := make([]string, 0, len(refs))
14✔
78
        for _, ref := range refs {
24✔
79
                refSpec, err := r.RefSpec(ref, "", fastForwardOnly)
10✔
80
                if err != nil {
11✔
81
                        return err
1✔
82
                }
1✔
83
                refSpecs = append(refSpecs, refSpec)
9✔
84
        }
85

86
        return r.FetchRefSpec(remoteName, refSpecs, opts...)
13✔
87
}
88

89
func (r *Repository) FetchObject(remoteName string, objectID Hash) error {
2✔
90
        args := []string{"fetch", remoteName, objectID.String()}
2✔
91
        _, err := r.executor(args...).executeString()
2✔
92
        if err != nil {
3✔
93
                return fmt.Errorf("unable to fetch object: %w", err)
1✔
94
        }
1✔
95

96
        return nil
1✔
97
}
98

99
func CloneAndFetchRepository(remoteURL, dir, initialBranch string, refs []string, bare bool) (*Repository, error) {
10✔
100
        if dir == "" {
11✔
101
                return nil, fmt.Errorf("target directory must be specified")
1✔
102
        }
1✔
103

104
        repo := &Repository{clock: clockwork.NewRealClock()}
9✔
105

9✔
106
        args := []string{"clone", remoteURL}
9✔
107
        if initialBranch != "" {
13✔
108
                initialBranch = strings.TrimPrefix(initialBranch, BranchRefPrefix)
4✔
109
                args = append(args, "--branch", initialBranch)
4✔
110
        }
4✔
111
        args = append(args, dir)
9✔
112

9✔
113
        if bare {
12✔
114
                args = append(args, "--bare")
3✔
115
                repo.gitDirPath = dir
3✔
116
        } else {
9✔
117
                repo.gitDirPath = path.Join(dir, ".git")
6✔
118
        }
6✔
119

120
        _, stdErr, err := repo.executor(args...).execute()
9✔
121
        if err != nil {
10✔
122
                return nil, fmt.Errorf("unable to clone repository: %s", stdErr)
1✔
123
        }
1✔
124

125
        if err := repo.ensureNoCompatObjectFormat(); err != nil {
8✔
NEW
126
                return nil, err
×
NEW
127
        }
×
128

129
        objectFormat, err := repo.readObjectFormat()
8✔
130
        if err != nil {
8✔
NEW
131
                return nil, err
×
NEW
132
        }
×
133
        repo.objectFormat = objectFormat
8✔
134

8✔
135
        return repo, repo.Fetch(DefaultRemoteName, refs, true)
8✔
136
}
137

138
func (r *Repository) CreateRemote(remoteName, remoteURL string) error {
17✔
139
        _, err := r.executor("remote", "add", remoteName, remoteURL).executeString()
17✔
140
        if err != nil {
18✔
141
                return fmt.Errorf("unable to add remote: %w", err)
1✔
142
        }
1✔
143

144
        return nil
16✔
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc