Skip to content

Commit a3d1a00

Browse files
authored
Merge pull request #74 from github/test-helpers
Better decouple the test from the runtime code
2 parents fe26775 + bb0bde6 commit a3d1a00

File tree

2 files changed

+155
-184
lines changed

2 files changed

+155
-184
lines changed

git/git.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"os"
1211
"os/exec"
1312
"path/filepath"
@@ -477,62 +476,6 @@ func (repo *Repository) NewObjectIter(args ...string) (
477476
}, in1, nil
478477
}
479478

480-
// CreateObject creates a new Git object, of the specified type, in
481-
// `Repository`. `writer` is a function that writes the object in `git
482-
// hash-object` input format. This is used for testing only.
483-
func (repo *Repository) CreateObject(t ObjectType, writer func(io.Writer) error) (OID, error) {
484-
cmd := repo.gitCommand("hash-object", "-w", "-t", string(t), "--stdin")
485-
in, err := cmd.StdinPipe()
486-
if err != nil {
487-
return OID{}, err
488-
}
489-
490-
out, err := cmd.StdoutPipe()
491-
if err != nil {
492-
return OID{}, err
493-
}
494-
495-
cmd.Stderr = os.Stderr
496-
497-
err = cmd.Start()
498-
if err != nil {
499-
return OID{}, err
500-
}
501-
502-
err = writer(in)
503-
err2 := in.Close()
504-
if err != nil {
505-
cmd.Wait()
506-
return OID{}, err
507-
}
508-
if err2 != nil {
509-
cmd.Wait()
510-
return OID{}, err2
511-
}
512-
513-
output, err := ioutil.ReadAll(out)
514-
err2 = cmd.Wait()
515-
if err != nil {
516-
return OID{}, err
517-
}
518-
if err2 != nil {
519-
return OID{}, err2
520-
}
521-
522-
return NewOID(string(bytes.TrimSpace(output)))
523-
}
524-
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-
536479
// Next returns the next object, or EOF when done.
537480
func (l *ObjectIter) Next() (OID, ObjectType, counts.Count32, error) {
538481
line, err := l.f.ReadString('\n')

0 commit comments

Comments
 (0)