Skip to content

Commit 26fd211

Browse files
committed
Example for src-d/go-git#923
1 parent 9bd7274 commit 26fd211

File tree

4 files changed

+118
-17
lines changed

4 files changed

+118
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
1414
.glide/
15+
16+
.idea
17+
temp

Gopkg.lock

Lines changed: 91 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Example for https://github.com/src-d/go-git/issues/708
1+
Example for https://github.com/src-d/go-git/issues/923

main.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,41 @@ import (
55
"gopkg.in/src-d/go-git.v4"
66
. "gopkg.in/src-d/go-git.v4/_examples"
77
"gopkg.in/src-d/go-git.v4/plumbing"
8-
"log"
98
"os"
10-
"time"
119
)
1210

1311
func main() {
1412
cloneDirPtr := flag.String("clone-dir", os.Args[0], "Directory to clone")
15-
cloneUrlPtr := flag.String("clone-url", "https://github.com/fkorotkov/go-git-clone-example", "URL to clone")
16-
refPtr := flag.String("ref", "refs/heads/master", "reference to clone")
17-
depthPtr := flag.Int("depth", 50, "depth to clone")
18-
singleBranchPtr := flag.Bool("single-branch", true, "clone only single branch")
13+
cloneUrlPtr := flag.String("clone-url", "https://github.com/flutter/flutter", "URL to clone")
14+
shaPtr := flag.String("sha", "", "sha to clone")
1915
flag.Parse()
2016

2117
cloneOptions := git.CloneOptions{
2218
URL: *cloneUrlPtr,
23-
ReferenceName: plumbing.ReferenceName(*refPtr),
24-
Depth: *depthPtr,
25-
SingleBranch: *singleBranchPtr,
19+
ReferenceName: plumbing.ReferenceName("refs/heads/master"),
20+
SingleBranch: true,
2621
Progress: os.Stdout,
27-
Tags: git.NoTags,
22+
Tags: git.NoTags,
2823
}
24+
repo, err := git.PlainClone(*cloneDirPtr, false, &cloneOptions)
25+
CheckIfError(err)
26+
reference, err := repo.Head()
27+
CheckIfError(err)
28+
Info("Cloned! Head at %s", reference)
29+
30+
workTree, err := repo.Worktree()
31+
CheckIfError(err)
2932

30-
start := time.Now()
31-
Info("Options %s", cloneOptions)
32-
_, err := git.PlainClone(*cloneDirPtr, false, &cloneOptions)
33-
elapsed := time.Now().Sub(start)
34-
log.Printf("Cloned in %s", elapsed)
33+
err = workTree.Reset(&git.ResetOptions{
34+
Commit: plumbing.NewHash(*shaPtr),
35+
Mode: git.HardReset,
36+
})
37+
CheckIfError(err)
38+
Info("Hard reseted to %s", *shaPtr)
3539

40+
status, err := workTree.Status()
3641
CheckIfError(err)
42+
Info("Status after reset: %s", status)
43+
44+
repo.Storer.Index()
3745
}

0 commit comments

Comments
 (0)