Skip to content

Commit 27a84b9

Browse files
committed
testutils.CreateReferencedOrphan(): new helper function
1 parent 8cbe129 commit 27a84b9

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

git_sizer_test.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,7 @@ func TestRefSelections(t *testing.T) {
140140
require.NoError(t, err)
141141

142142
for _, p := range references {
143-
oid := testutils.CreateObject(t, path, "blob", func(w io.Writer) error {
144-
_, err := fmt.Fprintf(w, "%s\n", p.refname)
145-
return err
146-
})
147-
148-
oid = testutils.CreateObject(t, path, "tree", func(w io.Writer) error {
149-
_, err = fmt.Fprintf(w, "100644 a.txt\x00%s", oid.Bytes())
150-
return err
151-
})
152-
153-
oid = testutils.CreateObject(t, path, "commit", func(w io.Writer) error {
154-
_, err := fmt.Fprintf(
155-
w,
156-
"tree %s\n"+
157-
"author Example <[email protected]> 1112911993 -0700\n"+
158-
"committer Example <[email protected]> 1112911993 -0700\n"+
159-
"\n"+
160-
"Commit for reference %s\n",
161-
oid, p.refname,
162-
)
163-
return err
164-
})
165-
166-
testutils.UpdateRef(t, path, p.refname, oid)
143+
testutils.CreateReferencedOrphan(t, path, p.refname)
167144
}
168145

169146
executable, err := exec.LookPath("bin/git-sizer")

internal/testutils/repoutils.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ func AddFile(t *testing.T, repoPath string, relativePath, contents string) {
104104
require.NoErrorf(t, cmd.Run(), "adding file %q", relativePath)
105105
}
106106

107+
func CreateReferencedOrphan(t *testing.T, repoPath string, refname string) {
108+
t.Helper()
109+
110+
oid := CreateObject(t, repoPath, "blob", func(w io.Writer) error {
111+
_, err := fmt.Fprintf(w, "%s\n", refname)
112+
return err
113+
})
114+
115+
oid = CreateObject(t, repoPath, "tree", func(w io.Writer) error {
116+
_, err := fmt.Fprintf(w, "100644 a.txt\x00%s", oid.Bytes())
117+
return err
118+
})
119+
120+
oid = CreateObject(t, repoPath, "commit", func(w io.Writer) error {
121+
_, err := fmt.Fprintf(
122+
w,
123+
"tree %s\n"+
124+
"author Example <[email protected]> 1112911993 -0700\n"+
125+
"committer Example <[email protected]> 1112911993 -0700\n"+
126+
"\n"+
127+
"Commit for reference %s\n",
128+
oid, refname,
129+
)
130+
return err
131+
})
132+
133+
UpdateRef(t, repoPath, refname, oid)
134+
}
135+
107136
func AddAuthorInfo(cmd *exec.Cmd, timestamp *time.Time) {
108137
cmd.Env = append(cmd.Env,
109138
"GIT_AUTHOR_NAME=Arthur",

0 commit comments

Comments
 (0)