Skip to content

Commit b4db7cd

Browse files
committed
updateRef(): make into a test helper function
It's only needed for testing.
1 parent 7924a9e commit b4db7cd

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

git/git.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,6 @@ func (repo *Repository) CreateObject(t ObjectType, writer func(io.Writer) error)
522522
return NewOID(string(bytes.TrimSpace(output)))
523523
}
524524

525-
func (repo *Repository) UpdateRef(refname string, oid OID) error {
526-
var cmd *exec.Cmd
527-
528-
if oid == NullOID {
529-
cmd = repo.gitCommand("update-ref", "-d", refname)
530-
} else {
531-
cmd = repo.gitCommand("update-ref", refname, oid.String())
532-
}
533-
return cmd.Run()
534-
}
535-
536525
// Next returns the next object, or EOF when done.
537526
func (l *ObjectIter) Next() (OID, ObjectType, counts.Count32, error) {
538527
line, err := l.f.ReadString('\n')

git_sizer_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ func gitCommand(t *testing.T, repoPath string, args ...string) *exec.Cmd {
3333
return cmd
3434
}
3535

36+
func updateRef(t *testing.T, repoPath string, refname string, oid git.OID) error {
37+
t.Helper()
38+
39+
var cmd *exec.Cmd
40+
41+
if oid == git.NullOID {
42+
cmd = gitCommand(t, repoPath, "update-ref", "-d", refname)
43+
} else {
44+
cmd = gitCommand(t, repoPath, "update-ref", refname, oid.String())
45+
}
46+
return cmd.Run()
47+
}
48+
3649
func addFile(t *testing.T, repoPath string, repo *git.Repository, relativePath, contents string) {
3750
dirPath := filepath.Dir(relativePath)
3851
if dirPath != "." {
@@ -119,7 +132,7 @@ func newGitBomb(
119132
})
120133
require.NoError(t, err)
121134

122-
err = repo.UpdateRef("refs/heads/master", oid)
135+
err = updateRef(t, repo.Path(), "refs/heads/master", oid)
123136
require.NoError(t, err)
124137

125138
return repo

0 commit comments

Comments
 (0)