func (t TestRepo) SaveFile(filename, subdir, content string) {
	d := filepath.Join(t.Workdir(), subdir)
	err := os.MkdirAll(d, 0700)
	CheckFatal(t.test, err)
	err = ioutil.WriteFile(filepath.Join(d, filename), []byte(content), 0644)
	CheckFatal(t.test, err)
}
SaveFile creates a file within the git repo project
package util
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"testing"
	"time"
	"github.com/libgit2/git2go"
)
type TestRepo struct {
	repo *git.Repository
	test *testing.T
}
func (t TestRepo) Repo() *git.Repository {
	return t.repo
}
func NewTestRepo(t *testing.T, bare bool) TestRepo {
	path, err := ioutil.TempDir("", "gtm")
	CheckFatal(t, err)
	repo, err := git.InitRepository(path, bare)
	CheckFatal(t, err)
	return TestRepo{repo: repo, test: t}
}
func (t TestRepo) Seed() {
	t.SaveFile("README", "", "foo\n")
	treeOid := t.Stage("README")
	t.Commit(treeOid)
}
func (t TestRepo) Remove() {
	var repoPath string
	if t.repo.IsBare() {
		repoPath = t.repo.Path()
	} else {
		repoPath = t.repo.Workdir()
	}
	if !strings.Contains(filepath.Clean(repoPath), filepath.Clean(os.TempDir())) {
		CheckFatal(t.test, fmt.Errorf("Unable to remove, repoPath %s is not within %s", repoPath, os.TempDir()))
		return
	}
	err := os.RemoveAll(repoPath)
	if err != nil {
		_, _ = fmt.Fprintln(os.Stderr, err)
	}
	t.repo.Free()
}
func (t TestRepo) Workdir() string {
	return filepath.Clean(t.repo.Workdir())
}
func (t TestRepo) Path() string {
	return filepath.Clean(t.repo.Path())
}
func (t TestRepo) Stage(files ...string) *git.Oid {
	idx, err := t.repo.Index()
	CheckFatal(t.test, err)
	for _, f := range files {
		err = idx.AddByPath(filepath.ToSlash(f))
		CheckFatal(t.test, err)
	}
	treeID, err := idx.WriteTreeTo(t.repo)
	CheckFatal(t.test, err)
	err = idx.Write()
	CheckFatal(t.test, err)
	return treeID
}
func (t TestRepo) Commit(treeID *git.Oid) *git.Oid {
	loc, err := time.LoadLocation("America/Chicago")
	CheckFatal(t.test, err)
	sig := &git.Signature{
		Name:  "Rand Om Hacker",
		Email: "random@hacker.com",
		When:  time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
	}
	headUnborn, err := t.repo.IsHeadUnborn()
	CheckFatal(t.test, err)
	var currentTip *git.Commit
	if !headUnborn {
		currentBranch, err := t.repo.Head()
		CheckFatal(t.test, err)
		currentTip, err = t.repo.LookupCommit(currentBranch.Target())
		CheckFatal(t.test, err)
	}
	message := "This is a commit\n"
	tree, err := t.repo.LookupTree(treeID)
	CheckFatal(t.test, err)
	var commitID *git.Oid
	if headUnborn {
		commitID, err = t.repo.CreateCommit("HEAD", sig, sig, message, tree)
	} else {
		commitID, err = t.repo.CreateCommit("HEAD", sig, sig, message, tree,
			currentTip)
	}
	CheckFatal(t.test, err)
	return commitID
}