Skip to content

Commit 193aeca

Browse files
committed
111
1 parent 49f2962 commit 193aeca

File tree

7 files changed

+48
-21
lines changed

7 files changed

+48
-21
lines changed

command.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
// CommandOptions contains additional options for running a Git command.
2121
type CommandOptions struct {
22-
// The additional environment variables to be passed to the underlying Git.
2322
Envs []string
2423
}
2524

repo_blame.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func (r *Repository) Blame(ctx context.Context, rev, file string, opts ...BlameO
2525
}
2626

2727
args := []string{"blame", "-l", "-s", rev, "--", file}
28-
2928
stdout, err := exec(ctx, r.path, args, opt.Envs)
3029
if err != nil {
3130
return nil, err

repo_commit.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func (r *Repository) CatFileCommit(ctx context.Context, rev string, opts ...CatF
9595
}
9696

9797
args := []string{"cat-file", "commit", commitID}
98-
9998
stdout, err := exec(ctx, r.path, args, opt.Envs)
10099
if err != nil {
101100
return nil, err
@@ -128,7 +127,6 @@ func (r *Repository) CatFileType(ctx context.Context, rev string, opts ...CatFil
128127
}
129128

130129
args := []string{"cat-file", "-t", rev}
131-
132130
typ, err := exec(ctx, r.path, args, opt.Envs)
133131
if err != nil {
134132
return "", err

repo_grep.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (r *Repository) Grep(ctx context.Context, pattern string, opts ...GrepOptio
7979
}
8080

8181
args := []string{"grep"}
82-
// Display full-name, line number and column number
8382
args = append(args, "--full-name", "--line-number", "--column")
8483
if opt.IgnoreCase {
8584
args = append(args, "--ignore-case")

repo_pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package git
66

77
import (
88
"context"
9+
"fmt"
910
"strings"
1011
)
1112

@@ -25,11 +26,10 @@ func (r *Repository) MergeBase(ctx context.Context, base, head string, opts ...M
2526
opt = opts[0]
2627
}
2728

28-
args := []string{"merge-base"}
29-
args = append(args, "--end-of-options", base, head)
30-
29+
args := []string{"merge-base", "--end-of-options", base, head}
3130
stdout, err := exec(ctx, r.path, args, opt.Envs)
3231
if err != nil {
32+
fmt.Printf("%+v\n", err)
3333
if isExitStatus(err, 1) {
3434
return "", ErrNoMergeBase
3535
}

repo_pull_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
)
1314

1415
func TestRepository_MergeBase(t *testing.T) {
@@ -25,28 +26,25 @@ func TestRepository_MergeBase(t *testing.T) {
2526
tests := []struct {
2627
base string
2728
head string
28-
opt MergeBaseOptions
29-
expMergeBase string
29+
opt MergeBaseOptions
30+
wantMergeBase string
3031
}{
3132
{
32-
base: "4e59b72440188e7c2578299fc28ea425fbe9aece",
33-
head: "0eedd79eba4394bbef888c804e899731644367fe",
34-
expMergeBase: "4e59b72440188e7c2578299fc28ea425fbe9aece",
33+
base: "4e59b72440188e7c2578299fc28ea425fbe9aece",
34+
head: "0eedd79eba4394bbef888c804e899731644367fe",
35+
wantMergeBase: "4e59b72440188e7c2578299fc28ea425fbe9aece",
3536
},
3637
{
37-
base: "master",
38-
head: "release-1.0",
39-
expMergeBase: "0eedd79eba4394bbef888c804e899731644367fe",
38+
base: "master",
39+
head: "release-1.0",
40+
wantMergeBase: "0eedd79eba4394bbef888c804e899731644367fe",
4041
},
4142
}
4243
for _, test := range tests {
4344
t.Run("", func(t *testing.T) {
4445
mb, err := testrepo.MergeBase(ctx, test.base, test.head, test.opt)
45-
if err != nil {
46-
t.Fatal(err)
47-
}
48-
49-
assert.Equal(t, test.expMergeBase, mb)
46+
require.NoError(t, err)
47+
assert.Equal(t, test.wantMergeBase, mb)
5048
})
5149
}
5250
}

tree_entry_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1213
)
1314

1415
func TestTreeEntry(t *testing.T) {
@@ -31,6 +32,39 @@ func TestTreeEntry(t *testing.T) {
3132
assert.Equal(t, "go.mod", e.Name())
3233
}
3334

35+
func TestTreeEntry_Size(t *testing.T) {
36+
ctx := context.Background()
37+
tree, err := testrepo.LsTree(ctx, "0eedd79eba4394bbef888c804e899731644367fe")
38+
require.NoError(t, err)
39+
40+
es, err := tree.Entries(ctx)
41+
require.NoError(t, err)
42+
43+
t.Run("blob", func(t *testing.T) {
44+
var entry *TreeEntry
45+
for _, e := range es {
46+
if e.Name() == "README.txt" {
47+
entry = e
48+
break
49+
}
50+
}
51+
require.NotNil(t, entry, "entry README.txt not found")
52+
assert.Equal(t, int64(795), entry.Size(ctx))
53+
})
54+
55+
t.Run("tree returns zero", func(t *testing.T) {
56+
var entry *TreeEntry
57+
for _, e := range es {
58+
if e.IsTree() {
59+
entry = e
60+
break
61+
}
62+
}
63+
require.NotNil(t, entry, "tree entry not found")
64+
assert.Equal(t, int64(0), entry.Size(ctx))
65+
})
66+
}
67+
3468
func TestEntries_Sort(t *testing.T) {
3569
ctx := context.Background()
3670
tree, err := testrepo.LsTree(ctx, "0eedd79eba4394bbef888c804e899731644367fe")

0 commit comments

Comments
 (0)