Skip to content

gitbase: do not skip repo when it has no head in squash #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions squash_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,16 @@ func (i *squashRemoteIter) Advance() error {
config = remote.Config()
}

fetch := i.urlPos
if fetch >= len(config.Fetch) {
fetch = len(config.Fetch) - 1
}

i.remote = &Remote{
RepoID: i.repo.ID,
Name: config.Name,
URL: config.URLs[i.urlPos],
Fetch: config.Fetch[i.urlPos].String(),
Fetch: config.Fetch[fetch].String(),
}

i.row = sql.NewRow(
Expand Down Expand Up @@ -344,11 +349,16 @@ func (i *squashRepoRemotesIter) Advance() error {
config = remote.Config()
}

fetch := i.urlPos
if fetch >= len(config.Fetch) {
fetch = len(config.Fetch) - 1
}

i.remote = &Remote{
RepoID: i.repos.Repository().ID,
Name: config.Name,
URL: config.URLs[i.urlPos],
Fetch: config.Fetch[i.urlPos].String(),
Fetch: config.Fetch[fetch].String(),
}

i.urlPos++
Expand Down Expand Up @@ -481,13 +491,10 @@ func (i *squashRefIter) Advance() error {
}

i.head, err = i.repo.Repo.Head()
if err != nil {
if err == plumbing.ErrReferenceNotFound || i.skipGitErrors {
i.repo = nil
continue
}

if err == plumbing.ErrReferenceNotFound {
logrus.WithField("repo", i.repo.ID).Debug("unable to get HEAD of repository")
} else if err != nil && !i.skipGitErrors {
return err
}
}

Expand Down Expand Up @@ -636,7 +643,6 @@ func (i *squashRepoRefsIter) Advance() error {

logrus.WithField("repo", i.repos.Repository().ID).
Debug("unable to get HEAD of repository")
continue
}
}

Expand Down
74 changes: 74 additions & 0 deletions squash_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gitbase

import (
"context"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -902,6 +903,79 @@ func setupWithIndex(
return ctx, index, cleanup
}

func TestRefsIterSiva(t *testing.T) {
path := filepath.Join("_testdata", "05893125684f2d3943cd84a7ab2b75e53668fba1.siva")
pool := NewRepositoryPool()
require.NoError(t, pool.AddSivaFile(path))

session := NewSession(pool)
ctx := sql.NewContext(context.Background(), sql.WithSession(session))

cases := []struct {
name string
iter ChainableIter
}{
{"all refs", NewAllRefsIter(nil, false)},
{"repo refs", NewRepoRefsIter(NewAllReposIter(nil), nil, false)},
}

expected := []sql.Row{
{
path,
"refs/heads/HEAD/015da2f4-6d89-7ec8-5ac9-a38329ea875b",
"dbfab055c70379219cbcf422f05316fdf4e1aed3",
},
{
path,
"refs/heads/master/015da2f4-6d89-7ec8-5ac9-a38329ea875b",
"dbfab055c70379219cbcf422f05316fdf4e1aed3",
},
}

for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
it, err := NewChainableRowIter(ctx, tt.iter)
require.NoError(err)

rows, err := sql.RowIterToRows(it)
require.NoError(err)

// remove all non-ref columns
for i := range rows {
rows[i] = rows[i][len(rows[i])-3:]
}

require.ElementsMatch(expected, rows)
})
}

t.Run("remote refs", func(t *testing.T) {
require := require.New(t)
it, err := NewChainableRowIter(
ctx,
NewRemoteRefsIter(NewAllRemotesIter(nil), nil),
)
require.NoError(err)

rows, err := sql.RowIterToRows(it)
require.NoError(err)

// remove all non-ref columns
for i := range rows {
rows[i] = rows[i][len(rows[i])-3:]
}

expected := []sql.Row{
expected[0], expected[1],
expected[0], expected[1],
expected[0], expected[1],
}

require.ElementsMatch(expected, rows)
})
}

type lookup struct {
values sql.IndexValueIter
}
Expand Down