blob: 0000f5e92740a61cfbb71535db2e1b508ca67e42 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package main
import (
"fmt"
"os"
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
)
// Open an existing repository in a specific folder.
func main() {
CheckArgs("<path>")
path := os.Args[1]
// We instance a new repository targeting the given path (the .git folder)
r, err := git.PlainOpen(path)
CheckIfError(err)
// Length of the HEAD history
Info("git rev-list HEAD --count")
// ... retrieving the HEAD reference
ref, err := r.Head()
CheckIfError(err)
// ... retrieving the commit object
commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
// ... calculating the commit history
commits, err := commit.History()
CheckIfError(err)
fmt.Println(len(commits))
}
|