A self-contained Golang package for parsing (and serializing) the Git Bundle Format v2 and v3, ex:
package main
import (
"bufio"
"log"
"os"
gitbundle "github.com/bored-engineer/git-bundle"
)
func main() {
f, err := os.Open("<path to bundle file>")
if err != nil {
log.Fatalf("os.Open failed: %v", err)
}
defer f.Close()
br := bufio.NewReader(f)
bundle, err := gitbundle.Parse(br)
if err != nil {
log.Fatalf("gitbundle.Parse failed: %v", err)
}
for refname, objID := range bundle.References.Map() {
log.Printf("%s: %s", refname, objID)
}
}When Parse returns, the *bufio.Reader position will be at the start of the git packfile section and can be directly read/passed to another package such as github.com/go-git/go-git/v5/plumbing/format/packfile package.
Similarly, when (*Bundle).WriteTo is used only the bundle header will be written to the provided io.Writer, appending the actual packfile contents is left as an exercise for the user.