aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/basic/main.go41
-rw-r--r--repository.go3
2 files changed, 44 insertions, 0 deletions
diff --git a/examples/basic/main.go b/examples/basic/main.go
new file mode 100644
index 0000000..c922d35
--- /dev/null
+++ b/examples/basic/main.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+
+ "gopkg.in/src-d/go-git.v2"
+)
+
+func main() {
+ fmt.Printf("Retrieving %q ...\n", os.Args[2])
+ r, err := git.NewRepository(os.Args[2], nil)
+ if err != nil {
+ panic(err)
+ }
+
+ if err := r.Pull("origin", "refs/heads/master"); err != nil {
+ panic(err)
+ }
+
+ dumpCommits(r)
+}
+
+func dumpCommits(r *git.Repository) {
+ iter := r.Commits()
+ defer iter.Close()
+
+ for {
+ commit, err := iter.Next()
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+
+ panic(err)
+ }
+
+ fmt.Println(commit)
+ }
+}
diff --git a/repository.go b/repository.go
index 5deddfb..8f1aac2 100644
--- a/repository.go
+++ b/repository.go
@@ -53,6 +53,9 @@ func NewPlainRepository() *Repository {
}
}
+// Pull connect and fetch the given branch from the given remote, the branch
+// should be provided with the full path not only the abbreviation, eg.:
+// "refs/heads/master"
func (r *Repository) Pull(remoteName, branch string) (err error) {
remote, ok := r.Remotes[remoteName]
if !ok {