From 2bda70316de41db59695aa3bff69ffd930283387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 2 Sep 2020 14:48:28 +0200 Subject: [PATCH] repository: more go-git implementation --- repository/gogit.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/repository/gogit.go b/repository/gogit.go index f115fab5..35283706 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -12,6 +12,8 @@ import ( gogit "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/filemode" + "github.com/go-git/go-git/v5/plumbing/object" "github.com/MichaelMure/git-bug/util/lamport" ) @@ -285,10 +287,37 @@ func (repo *GoGitRepo) ReadData(hash Hash) ([]byte, error) { } func (repo *GoGitRepo) StoreTree(mapping []TreeEntry) (Hash, error) { - panic("implement me") + var tree object.Tree + + for _, entry := range mapping { + mode := filemode.Regular + if entry.ObjectType == Tree { + mode = filemode.Dir + } + + tree.Entries = append(tree.Entries, object.TreeEntry{ + Name: entry.Name, + Mode: mode, + Hash: plumbing.NewHash(entry.Hash.String()), + }) + } + + obj := repo.r.Storer.NewEncodedObject() + err := tree.Encode(obj) + if err != nil { + return "", err + } + + hash, err := repo.r.Storer.SetEncodedObject(obj) + if err != nil { + return "", err + } + + return Hash(hash.String()), nil } func (repo *GoGitRepo) ReadTree(hash Hash) ([]TreeEntry, error) { + // repo.r.TreeObject() panic("implement me") } @@ -313,7 +342,7 @@ func (repo *GoGitRepo) UpdateRef(ref string, hash Hash) error { } func (repo *GoGitRepo) RemoveRef(ref string) error { - panic("implement me") + return repo.r.Storer.RemoveReference(plumbing.ReferenceName(ref)) } func (repo *GoGitRepo) ListRefs(refspec string) ([]string, error) {