-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (41 loc) · 901 Bytes
/
main.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"flag"
"fmt"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/storage/memory"
)
var repo string
func main() {
flag.StringVar(&repo, "repo", "", "repository url")
flag.Parse()
r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: repo,
})
youSilly(err)
ref, err := r.Head()
youSilly(err)
it, err := r.Log(&git.LogOptions{
From: ref.Hash(),
Order: git.LogOrderCommitterTime,
})
youSilly(err)
commits := make([]string, 0)
err = it.ForEach(func(c *object.Commit) error {
commits = append(commits, c.Hash.String()[:8])
return nil
})
youSilly(err)
for i, j := 0, len(commits)-1; i < j; i, j = i+1, j-1 {
commits[i], commits[j] = commits[j], commits[i]
}
for _, h := range commits {
fmt.Println(h)
}
}
func youSilly(err error) {
if err != nil {
panic(err)
}
}