aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-09-02 14:48:28 +0200
committerMichael Muré <batolettre@gmail.com>2020-09-29 20:42:21 +0200
commit2bda70316de41db59695aa3bff69ffd930283387 (patch)
treed286db98bff549f7ec797d8029e4e45eaab73ff7
parent9c1087e18d2b4f7d5d9f0e98136933d05ce13827 (diff)
downloadgit-bug-2bda70316de41db59695aa3bff69ffd930283387.tar.gz
repository: more go-git implementation
-rw-r--r--repository/gogit.go33
1 files 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) {