aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md1
-rw-r--r--examples/common_test.go1
-rw-r--r--examples/progress/main.go32
3 files changed, 34 insertions, 0 deletions
diff --git a/examples/README.md b/examples/README.md
index 8762b4a..334664f 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -7,6 +7,7 @@ Here you can find a list of annotated _go-git_ examples:
- [open](open/main.go) - Opening a existing repository cloned by _git_
- [clone](clone/main.go) - Cloning a repository
- [remotes](remotes/main.go) - Working with remotes: adding, removing, etc
+- [progress](progress/main.go) - Priting the progress information from the sideband
### Advanced
- [custom_http](custom_http/main.go) - Replacing the HTTP client using a custom one
diff --git a/examples/common_test.go b/examples/common_test.go
index 1059f4b..e75b492 100644
--- a/examples/common_test.go
+++ b/examples/common_test.go
@@ -18,6 +18,7 @@ var args = map[string][]string{
"showcase": []string{defaultURL},
"custom_http": []string{defaultURL},
"clone": []string{defaultURL, tempFolder()},
+ "progress": []string{defaultURL, tempFolder()},
"open": []string{filepath.Join(cloneRepository(defaultURL, tempFolder()), ".git")},
}
diff --git a/examples/progress/main.go b/examples/progress/main.go
new file mode 100644
index 0000000..e0e4c1d
--- /dev/null
+++ b/examples/progress/main.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "os"
+
+ "gopkg.in/src-d/go-git.v4"
+ . "gopkg.in/src-d/go-git.v4/examples"
+)
+
+func main() {
+ CheckArgs("<url>", "<directory>")
+ url := os.Args[1]
+ directory := os.Args[2]
+
+ r, err := git.NewFilesystemRepository(directory)
+ CheckIfError(err)
+
+ // as git does, when you make a clone, pull or some other operations, the
+ // server sends information via the sideband, this information can being
+ // collected provinding a io.Writer to the repository
+ r.Progress = os.Stdout
+
+ // Clone the given repository to the given directory
+ Info("git clone %s %s", url, directory)
+
+ err = r.Clone(&git.CloneOptions{
+ URL: url,
+ Depth: 1,
+ })
+
+ CheckIfError(err)
+}