aboutsummaryrefslogtreecommitdiffstats
path: root/_examples/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to '_examples/common_test.go')
-rw-r--r--_examples/common_test.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/_examples/common_test.go b/_examples/common_test.go
index 86205fe..9eeb643 100644
--- a/_examples/common_test.go
+++ b/_examples/common_test.go
@@ -17,6 +17,7 @@ var defaultURL = "https://github.com/git-fixtures/basic.git"
var args = map[string][]string{
"checkout": []string{defaultURL, tempFolder(), "35e85108805c84807bc66a02d91535e1e24b38b9"},
"clone": []string{defaultURL, tempFolder()},
+ "context": []string{defaultURL, tempFolder()},
"commit": []string{cloneRepository(defaultURL, tempFolder())},
"custom_http": []string{defaultURL},
"open": []string{cloneRepository(defaultURL, tempFolder())},
@@ -24,6 +25,7 @@ var args = map[string][]string{
"push": []string{setEmptyRemote(cloneRepository(defaultURL, tempFolder()))},
"showcase": []string{defaultURL, tempFolder()},
"tag": []string{cloneRepository(defaultURL, tempFolder())},
+ "pull": []string{createRepositoryWithRemote(tempFolder(), defaultURL)},
}
var ignored = map[string]bool{}
@@ -88,13 +90,28 @@ func cloneRepository(url, folder string) string {
}
func createBareRepository(dir string) string {
- cmd := exec.Command("git", "init", "--bare", dir)
+ return createRepository(dir, true)
+}
+
+func createRepository(dir string, isBare bool) string {
+ var cmd *exec.Cmd
+ if isBare {
+ cmd = exec.Command("git", "init", "--bare", dir)
+ } else {
+ cmd = exec.Command("git", "init", dir)
+ }
err := cmd.Run()
CheckIfError(err)
return dir
}
+func createRepositoryWithRemote(local, remote string) string {
+ createRepository(local, false)
+ addRemote(local, remote)
+ return local
+}
+
func setEmptyRemote(dir string) string {
remote := createBareRepository(tempFolder())
setRemote(dir, remote)
@@ -108,6 +125,13 @@ func setRemote(local, remote string) {
CheckIfError(err)
}
+func addRemote(local, remote string) {
+ cmd := exec.Command("git", "remote", "add", "origin", remote)
+ cmd.Dir = local
+ err := cmd.Run()
+ CheckIfError(err)
+}
+
func testExample(t *testing.T, name, example string) {
cmd := exec.Command("go", append([]string{
"run", filepath.Join(example),