Created
November 14, 2017 15:24
-
-
Save kelseyhightower/2fb4c4a5079d3bf7a2f952545ecb75ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"golang.org/x/oauth2/google" | |
"gopkg.in/src-d/go-git.v4" | |
"gopkg.in/src-d/go-git.v4/config" | |
"gopkg.in/src-d/go-git.v4/plumbing/transport/http" | |
) | |
func main() { | |
ts, err := google.DefaultTokenSource(context.Background()) | |
if err != nil { | |
log.Fatal(err) | |
} | |
token, err := ts.Token() | |
if err != nil { | |
log.Fatal(err) | |
} | |
r, err := git.PlainClone("upstream", false, &git.CloneOptions{ | |
RemoteName: "origin", | |
URL: "https://github.com/kelseyhightower/pipeline-application.git", | |
Tags: git.AllTags, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
_, err = r.CreateRemote(&config.RemoteConfig{ | |
Name: "google", | |
URLs: []string{"https://source.developers.google.com/p/pipeline-tutorial/r/pipeline-application"}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
list, err := r.Remotes() | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, r := range list { | |
fmt.Println(r) | |
} | |
err = r.Push(&git.PushOptions{ | |
RemoteName: "google", | |
Auth: http.NewBasicAuth("[email protected]", token.AccessToken), | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment