From 79fe156d307a9c7b294aa92c741dc0c2759a1894 Mon Sep 17 00:00:00 2001 From: Vadzim Ramanenka Date: Mon, 17 Jul 2017 13:12:43 +0300 Subject: Add binding for `git_index_add_frombuffer` --- index_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'index_test.go') diff --git a/index_test.go b/index_test.go index f47dace..d882809 100644 --- a/index_test.go +++ b/index_test.go @@ -149,6 +149,30 @@ func TestIndexRemoveDirectory(t *testing.T) { } } +func TestIndexAddFromBuffer(t *testing.T) { + t.Parallel() + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + idx, err := repo.Index() + checkFatal(t, err) + + entry := IndexEntry{ + Path: "README", + Mode: FilemodeBlob, + } + + err = idx.AddFromBuffer(&entry, []byte("foo\n")) + checkFatal(t, err) + + treeId, err := idx.WriteTreeTo(repo) + checkFatal(t, err) + + if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" { + t.Fatalf("%v", treeId.String()) + } +} + func TestIndexAddAllNoCallback(t *testing.T) { t.Parallel() repo := createTestRepo(t) -- cgit v1.2.3 From f969cc900dde4ba92c814823bc004bd1870079a9 Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Fri, 4 Jan 2019 13:18:54 +0000 Subject: Bump vendored libgit2 to fba70a9d5f This includes updating the `Index.WriteTreeTo` test as it was abusing an oversight of the object creation safety checks and creating a tree referencing a non-existent blob. Instead we update it to the primary purpose of this method which is to write into a repository from an unattached index. --- index_test.go | 26 +++++++++++++++++++++----- vendor/libgit2 | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'index_test.go') diff --git a/index_test.go b/index_test.go index f47dace..43644fa 100644 --- a/index_test.go +++ b/index_test.go @@ -3,6 +3,7 @@ package git import ( "io/ioutil" "os" + "path" "runtime" "testing" ) @@ -59,14 +60,29 @@ func TestIndexWriteTreeTo(t *testing.T) { repo := createTestRepo(t) defer cleanupTestRepo(t, repo) - repo2 := createTestRepo(t) - defer cleanupTestRepo(t, repo2) + idx, err := NewIndex() + checkFatal(t, err) - idx, err := repo.Index() + odb, err := repo.Odb() checkFatal(t, err) - err = idx.AddByPath("README") + + content, err := ioutil.ReadFile(path.Join(repo.Workdir(), "README")) + checkFatal(t, err) + + id, err := odb.Write(content, ObjectBlob) checkFatal(t, err) - treeId, err := idx.WriteTreeTo(repo2) + + err = idx.Add(&IndexEntry{ + Mode: FilemodeBlob, + Uid: 0, + Gid: 0, + Size: uint32(len(content)), + Id: id, + Path: "README", + }) + checkFatal(t, err) + + treeId, err := idx.WriteTreeTo(repo) checkFatal(t, err) if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" { diff --git a/vendor/libgit2 b/vendor/libgit2 index 838a2f2..fba70a9 160000 --- a/vendor/libgit2 +++ b/vendor/libgit2 @@ -1 +1 @@ -Subproject commit 838a2f2918b6d9fad8768d2498575ff5d75c35f0 +Subproject commit fba70a9d5f1fa433968a3dfd51e3153c8eebe834 -- cgit v1.2.3