diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-01-15 17:12:59 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2018-01-15 17:12:59 +0100 |
commit | 4d43799bf111a66b204312c79f1d0dd0d96108b1 (patch) | |
tree | b1e536bf01a391dc762c3b92283dda75e4d54b5b /_examples/branch_add_remove | |
parent | 71e438ee1c3bdca714f138fcc6bb8c084989a521 (diff) | |
download | go-git-4d43799bf111a66b204312c79f1d0dd0d96108b1.tar.gz |
_examples: branch example improvements
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
Diffstat (limited to '_examples/branch_add_remove')
-rw-r--r-- | _examples/branch_add_remove/main.go | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/_examples/branch_add_remove/main.go b/_examples/branch_add_remove/main.go deleted file mode 100644 index 4eb4089..0000000 --- a/_examples/branch_add_remove/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "os" - - "gopkg.in/src-d/go-git.v4" - . "gopkg.in/src-d/go-git.v4/_examples" - "gopkg.in/src-d/go-git.v4/plumbing" -) - -// Basic example of how to checkout a specific commit. -func main() { - CheckArgs("<url>", "<directory>") - url, directory := os.Args[1], os.Args[2] - - // Clone the given repository to the given directory - Info("git clone %s %s", url, directory) - r, err := git.PlainClone(directory, false, &git.CloneOptions{ - URL: url, - }) - CheckIfError(err) - - // ... retrieving the commit being pointed by HEAD - Info("git checkout -b <branch-name>") - - headRef, err := r.Head() - CheckIfError(err) - - // refs/heads/ is mandatory since go-git deals - // with references not branches. - branchName := "refs/heads/myBranch" - - // You can use plumbing.NewReferenceFromStrings if you want to checkout a branch at a specific commit. - ref := plumbing.NewHashReference(plumbing.ReferenceName(branchName), headRef.Hash()) - - err = r.Storer.SetReference(ref) - CheckIfError(err) - - Info("git branch -D <branch-name>") - - err = r.Storer.RemoveReference(ref.Name()) - CheckIfError(err) -} |