This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gitcache: refactor test setup to testutil
The git repo setup stuff is needed for other tests. Move it to a util package.
- Loading branch information
Brandon Philips
committed
Aug 1, 2019
1 parent
790afc8
commit 558be66
Showing
2 changed files
with
53 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package testutil | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
|
||
"gopkg.in/src-d/go-git.v4" | ||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
) | ||
|
||
func EmptyGitRepo(t *testing.T, url string) string { | ||
r, err := git.PlainInit(url, false) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
w, err := r.Worktree() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = ioutil.WriteFile(filepath.Join(url, "README"), []byte("Hello world"), 0755) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = w.Add("README") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = w.Commit("README\n", &git.CommitOptions{Author: &object.Signature{ | ||
Name: "Zohra", | ||
}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return filepath.Join(url, git.GitDirName) | ||
} |