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

gittuf / gittuf / 30044417887

23 Jul 2026 08:59PM UTC coverage: 78.204% (+0.06%) from 78.143%
30044417887

push

github

web-flow
Merge pull request #1500 from gittuf/fix-tests

pkg: Fix gitinterface test

1 of 1 new or added line in 1 file covered. (100.0%)

31 existing lines in 4 files now uncovered.

12834 of 16411 relevant lines covered (78.2%)

36.49 hits per line

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

88.89
/pkg/gitinterface/utils.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
        "testing"
11
)
12

13
// ResetDueToError reverses a change applied to a ref to the specified target
14
// ID. It is used to ensure a gittuf operation is atomic: if a gittuf operation
15
// fails, any changes made to the repository in refs/gittuf can be rolled back.
16
// Worktrees are not updated.
17
func (r *Repository) ResetDueToError(cause error, refName string, commitID Hash) error {
2✔
18
        if err := r.SetReference(refName, commitID); err != nil {
3✔
19
                return fmt.Errorf("unable to reset %s to %s, caused by following error: %w", refName, commitID.String(), cause)
1✔
20
        }
1✔
21
        return cause
1✔
22
}
23

24
func RemoteRef(refName, remoteName string) string {
10✔
25
        var remotePath string
10✔
26
        switch {
10✔
27
        case strings.HasPrefix(refName, BranchRefPrefix):
6✔
28
                // refs/heads/<path> -> refs/remotes/<remote>/<path>
6✔
29
                rest := strings.TrimPrefix(refName, BranchRefPrefix)
6✔
30
                remotePath = path.Join(RemoteRefPrefix, remoteName, rest)
6✔
31
        case strings.HasPrefix(refName, TagRefPrefix):
2✔
32
                // refs/tags/<path> -> refs/tags/<path>
2✔
33
                remotePath = refName
2✔
34
        default:
2✔
35
                // refs/<path> -> refs/remotes/<remote>/<path>
2✔
36
                rest := strings.TrimPrefix(refName, RefPrefix)
2✔
37
                remotePath = path.Join(RemoteRefPrefix, remoteName, rest)
2✔
38
        }
39

40
        return remotePath
10✔
41
}
42

43
// RestoreWorktree is a test helper to fix the worktree in tests where we need
44
// to operate in a checked out copy of the repository. This is primarily needed
45
// for support with older Git versions.
46
func (r *Repository) RestoreWorktree(t *testing.T) {
1✔
47
        t.Helper()
1✔
48

1✔
49
        worktree := r.gitDirPath
1✔
50
        if !r.IsBare() {
2✔
51
                worktree = strings.TrimSuffix(worktree, ".git") // TODO: this doesn't support detached git dir
1✔
52
        }
1✔
53

54
        if _, err := r.executor("restore", "--staged", ".").withDir(worktree).executeString(); err != nil {
1✔
UNCOV
55
                t.Fatal(err)
×
56
        }
×
57

58
        if _, err := r.executor("restore", ".").withDir(worktree).executeString(); err != nil {
1✔
59
                t.Fatal(err)
×
60
        }
×
61
}
62

63
func testNameToRefName(testName string) string {
59✔
64
        return BranchReferenceName(strings.ReplaceAll(testName, " ", "__"))
59✔
65
}
59✔
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