diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-31 23:09:28 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-31 23:09:52 +0100 |
commit | a6197bd8c459c7d10717bd9486c17f6c8b3f7f88 (patch) | |
tree | 63180ec210c66fda317c87197d2f6bab508406b6 /_examples/remotes | |
parent | 2308066c28d3cbbfb472fb634c3e10a1c7786cfc (diff) | |
download | go-git-a6197bd8c459c7d10717bd9486c17f6c8b3f7f88.tar.gz |
documentation changes
Diffstat (limited to '_examples/remotes')
-rw-r--r-- | _examples/remotes/main.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/_examples/remotes/main.go b/_examples/remotes/main.go new file mode 100644 index 0000000..362244b --- /dev/null +++ b/_examples/remotes/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + + "srcd.works/go-git.v4" + "srcd.works/go-git.v4/config" + . "srcd.works/go-git.v4/examples" + "srcd.works/go-git.v4/plumbing" + "srcd.works/go-git.v4/storage/memory" +) + +func main() { + // Create a new repository + Info("git init") + r, err := git.Init(memory.NewStorage(), nil) + CheckIfError(err) + + // Add a new remote, with the default fetch refspec + Info("git remote add example https://github.com/git-fixtures/basic.git") + _, err = r.CreateRemote(&config.RemoteConfig{ + Name: "example", + URL: "https://github.com/git-fixtures/basic.git", + }) + + CheckIfError(err) + + // List remotes from a repository + Info("git remotes -v") + + list, err := r.Remotes() + CheckIfError(err) + + for _, r := range list { + fmt.Println(r) + } + + // Pull using the create repository + Info("git pull example") + err = r.Pull(&git.PullOptions{ + RemoteName: "example", + }) + + CheckIfError(err) + + // List the branches + // > git show-ref + Info("git show-ref") + + refs, err := r.References() + CheckIfError(err) + + err = refs.ForEach(func(ref *plumbing.Reference) error { + // The HEAD is omitted in a `git show-ref` so we ignore the symbolic + // references, the HEAD + if ref.Type() == plumbing.SymbolicReference { + return nil + } + + fmt.Println(ref) + return nil + }) + + CheckIfError(err) + + // Delete the example remote + Info("git remote rm example") + + err = r.DeleteRemote("example") + CheckIfError(err) +} |