From 70f2d959b549cb3fc421254fa84c1123a1b21ea8 Mon Sep 17 00:00:00 2001 From: Bharat Nallan Date: Tue, 31 Mar 2020 08:35:28 -0700 Subject: [PATCH 1/2] return blob contents for blob and exec (#56) This PR adds an `or` conditional to return blob content if a file is an executable (entry mode 0100755). Prior to this `Blob` func only returned file contents if a file was of type blob (entry mode 010644). This in a resulted error to be returned for certain files that were for instance bash scripts which had the executable mode bit set. --- tree_blob.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree_blob.go b/tree_blob.go index 76e5d78c3..57fea1788 100644 --- a/tree_blob.go +++ b/tree_blob.go @@ -53,7 +53,7 @@ func (t *Tree) Blob(subpath string, opts ...LsTreeOptions) (*Blob, error) { return nil, err } - if e.IsBlob() { + if e.IsBlob() || e.IsExec() { return e.Blob(), nil } From b8bf9821bd1d54ac983c5b2eec84e930bdde326c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=E1=B4=8B=C9=B4=E1=B4=A1=E1=B4=8F=C9=B4?= Date: Wed, 1 Apr 2020 01:47:11 +0800 Subject: [PATCH 2/2] Add tests --- tree_blob_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tree_blob_test.go b/tree_blob_test.go index 82a74373e..6138be5b3 100644 --- a/tree_blob_test.go +++ b/tree_blob_test.go @@ -25,3 +25,33 @@ func TestTree_TreeEntry(t *testing.T) { assert.Equal(t, ObjectTree, e.Type()) assert.True(t, e.IsTree()) } + +func TestTree_Blob(t *testing.T) { + tree, err := testrepo.LsTree("d58e3ef9f123eea6857161c79275ee22b228f659") + if err != nil { + t.Fatal(err) + } + + t.Run("not a blob", func(t *testing.T) { + _, err := tree.Blob("src") + assert.Equal(t, ErrNotBlob, err) + }) + + t.Run("get a blob", func(t *testing.T) { + b, err := tree.Blob("README.txt") + if err != nil { + t.Fatal(err) + } + + assert.True(t, b.IsBlob()) + }) + + t.Run("get an executable as blob", func(t *testing.T) { + b, err := tree.Blob("run.sh") + if err != nil { + t.Fatal(err) + } + + assert.True(t, b.IsExec()) + }) +}