From 2308066c28d3cbbfb472fb634c3e10a1c7786cfc Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Tue, 31 Jan 2017 14:43:49 +0100 Subject: Updated README.md (Fixes #243) --- README.md | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5538dd8..5a379fc 100644 --- a/README.md +++ b/README.md @@ -27,20 +27,46 @@ go get -u srcd.works/go-git.v4/... Examples -------- -Cloning a repository and printing the history of HEAD, just like `git log` does - > Please note that the functions `CheckIfError` and `Info` used in the examples are from the [examples package](https://github.com/src-d/go-git/blob/master/examples/common.go#L17) just to be used in the examples. +### Basic example + +A basic example that mimics the standard `git clone` command + ```go -// Instances an in-memory git repository -r := git.NewMemoryRepository() +// Clone the given repository to the given directory +Info("git clone https://github.com/src-d/go-git") + +_, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{ + URL: "https://github.com/src-d/go-git", + Progress: os.Stdout, +}) + +CheckIfError(err) +``` + +Outputs: +``` +Counting objects: 4924, done. +Compressing objects: 100% (1333/1333), done. +Total 4924 (delta 530), reused 6 (delta 6), pack-reused 3533 +``` + +### In-memory example -// Clones the given repository, creating the remote, the local branches -// and fetching the objects, exactly as: +Cloning a repository into memory and printing the history of HEAD, just like `git log` does + + +```go +// Clones the given repository in memory, creating the remote, the local +// branches and fetching the objects, exactly as: Info("git clone https://github.com/src-d/go-siva") -err := r.Clone(&git.CloneOptions{URL: "https://github.com/src-d/go-siva"}) +r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ + URL: "https://github.com/src-d/go-siva", +}) + CheckIfError(err) // Gets the HEAD history from HEAD, just like does: -- cgit