diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/common_test.go | 23 | ||||
-rw-r--r-- | examples/push/main.go | 22 |
2 files changed, 45 insertions, 0 deletions
diff --git a/examples/common_test.go b/examples/common_test.go index e75b492..9ec1f05 100644 --- a/examples/common_test.go +++ b/examples/common_test.go @@ -2,6 +2,7 @@ package examples import ( "flag" + "fmt" "go/build" "io/ioutil" "os" @@ -20,6 +21,7 @@ var args = map[string][]string{ "clone": []string{defaultURL, tempFolder()}, "progress": []string{defaultURL, tempFolder()}, "open": []string{filepath.Join(cloneRepository(defaultURL, tempFolder()), ".git")}, + "push": []string{setEmptyRemote(filepath.Join(cloneRepository(defaultURL, tempFolder()), ".git"))}, } var ignored = map[string]bool{ @@ -85,6 +87,27 @@ func cloneRepository(url, folder string) string { return folder } +func createBareRepository(dir string) string { + cmd := exec.Command("git", "init", "--bare", dir) + err := cmd.Run() + CheckIfError(err) + + return dir +} + +func setEmptyRemote(dir string) string { + remote := createBareRepository(tempFolder()) + setRemote(dir, fmt.Sprintf("file://%s", remote)) + return dir +} + +func setRemote(local, remote string) { + cmd := exec.Command("git", "remote", "set-url", "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), diff --git a/examples/push/main.go b/examples/push/main.go new file mode 100644 index 0000000..9a30599 --- /dev/null +++ b/examples/push/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "os" + + "gopkg.in/src-d/go-git.v4" + . "gopkg.in/src-d/go-git.v4/examples" +) + +func main() { + CheckArgs("<repo path>") + repoPath := os.Args[1] + + repo, err := git.NewFilesystemRepository(repoPath) + CheckIfError(err) + + err = repo.Push(&git.PushOptions{}) + CheckIfError(err) + + fmt.Print("pushed") +} |