aboutsummaryrefslogblamecommitdiffstats
path: root/_examples/open/main.go
blob: 063c2770368af4c43945bf7927d553116a92e70a (plain) (tree)
1
2
3
4
5
6
7
8




             
 
                              
                                          


             

                           
 
                                                                                  
                                     
                         
 

                                         
 


                                            
 


                                           
 


                                             
 
                                 
 
package main

import (
	"fmt"
	"os"

	"srcd.works/go-git.v4"
	. "srcd.works/go-git.v4/_examples"
)

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.Commit(ref.Hash())
	CheckIfError(err)

	// ... calculating the commit history
	commits, err := commit.History()
	CheckIfError(err)

	fmt.Println(len(commits))
}