Skip to content

Commit

Permalink
[#200] Make the GitLogItems.add public
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad ATWI authored and mengdaming committed Jan 3, 2023
1 parent f4f746b commit 86be1cd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/vcs/git_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func New(dir string) (GitInterface, error) {
return newGitImpl(plainOpen, dir)
}

// newGitImpl initializes a gitImpl instance
func newGitImpl(initRepo func(string) (*git.Repository, billy.Filesystem, error), dir string) (*gitImpl, error) {
var g = gitImpl{
baseDir: dir,
Expand Down Expand Up @@ -332,7 +333,7 @@ func (g *gitImpl) Log(msgFilter func(msg string) bool) (logs GitLogItems, err er
}
_ = cIter.ForEach(func(c *object.Commit) error {
if msgFilter == nil || msgFilter(c.Message) {
logs.add(NewGitLogItem(c.Hash.String(), c.Committer.When.UTC(), c.Message))
logs.Add(NewGitLogItem(c.Hash.String(), c.Committer.When.UTC(), c.Message))
}
return nil
})
Expand Down
3 changes: 2 additions & 1 deletion src/vcs/git_log_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (items *GitLogItems) sortByDate() {
})
}

func (items *GitLogItems) add(d GitLogItem) {
// Add adds a GitLogItem to the GitLogItems collection
func (items *GitLogItems) Add(d GitLogItem) {
*items = append(*items, d)
}

Expand Down
4 changes: 2 additions & 2 deletions src/vcs/git_log_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import (
func Test_add_regular_git_log_item(t *testing.T) {
var items GitLogItems
item := NewGitLogItem("xxx", time.Now(), "some message")
items.add(item)
items.Add(item)
assert.Len(t, items, 1)
assert.Contains(t, items, item)
}

func Test_add_empty_git_log_item(t *testing.T) {
var items GitLogItems
item := NewGitLogItem("", time.Time{}, "")
items.add(item)
items.Add(item)
assert.Len(t, items, 1)
}

Expand Down
2 changes: 1 addition & 1 deletion src/vcs/git_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (g *GitFake) Log(msgFilter func(msg string) bool) (logs GitLogItems, err er

for _, log := range g.settings.Logs {
if msgFilter(log.Message) {
logs.add(log)
logs.Add(log)
}
}
return
Expand Down

0 comments on commit 86be1cd

Please sign in to comment.