Skip to content

Commit

Permalink
Warily treat empty pattern (re tsuru#120 and tsuru#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Jul 24, 2014
1 parent 40ce1be commit 9f7f03e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ func (*GitContentRetriever) GetForEachRef(repo, pattern string) ([]map[string]st
return nil, fmt.Errorf("Error when trying to obtain the refs of repository %s (%s).", repo, err)
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
if len(lines) == 1 && len(lines[0]) == 0 {
return nil, nil
}
objectCount := len(lines)
objects := make([]map[string]string, objectCount)
objectCount = 0
Expand Down
17 changes: 17 additions & 0 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,20 @@ func (s *S) TestGetForEachRefIntegrationSubjectWithTab(c *gocheck.C) {
c.Assert(refs[1]["authorEmail"], gocheck.Equals, "<much@email.com>")
c.Assert(refs[1]["subject"], gocheck.Equals, "will\tbark")
}

func (s *S) TestGetForEachRefIntegrationWhenNoPatternSupplied(c *gocheck.C) {
oldBare := bare
bare = "/tmp"
repo := "gandalf-test-repo"
file := "README"
content := "much WOW"
cleanUp, errCreate := CreateTestRepository(bare, repo, file, content)
defer func() {
cleanUp()
bare = oldBare
}()
c.Assert(errCreate, gocheck.IsNil)
refs, err := GetForEachRef("gandalf-test-repo", "")
c.Assert(refs, gocheck.IsNil)
c.Assert(err, gocheck.IsNil)
}

0 comments on commit 9f7f03e

Please sign in to comment.