Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
repository/GetForEachRef: trim only a newline form output
Browse files Browse the repository at this point in the history
Trimming space from the command output may ruin the last line in some
cases where author info and subject line are empty.
  • Loading branch information
scorphus committed Sep 16, 2015
1 parent 1fc2349 commit 4591617
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (*GitContentRetriever) GetForEachRef(repo, pattern string) ([]Ref, error) {
if err != nil {
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")
lines := strings.Split(strings.TrimSuffix(string(out), "\n"), "\n")
objectCount := len(lines)
if len(lines) == 1 && len(lines[0]) == 0 {
objectCount = 0
Expand Down
20 changes: 20 additions & 0 deletions repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,26 @@ func (s *S) TestGetForEachRefIntegrationWhenPatternInvalid(c *check.C) {
c.Assert(err.Error(), check.Equals, "Error when trying to obtain the refs of repository gandalf-test-repo (exit status 129).")
}

func (s *S) TestGetForEachRefWithSomeEmptyFields(c *check.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, check.IsNil)
tmpdir, err := commandmocker.Add("git", "ec083c5f40be15e2bf5a84efe83d8f4723a6dcc0\tmaster\t\t\t\t\t\t\t")
c.Assert(err, check.IsNil)
defer commandmocker.Remove(tmpdir)
refs, err := GetForEachRef(repo, "")
c.Assert(err, check.IsNil)
c.Assert(refs, check.HasLen, 1)
}

func (s *S) TestGetForEachRefOutputInvalid(c *check.C) {
oldBare := bare
bare = "/tmp"
Expand Down

0 comments on commit 4591617

Please sign in to comment.