From 90d67bb648ae32d5b1a0f7b1af011da6dfb24315 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 19 Dec 2016 23:36:44 +0100 Subject: remote: add Push (#178) * remote: add Push. * add Push method to Remote. * add method Push to Repository. * examples: add push example. * requested changes * add tests, fixes --- examples/common_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'examples/common_test.go') 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), -- cgit