diff --git a/src/iterator.c b/src/iterator.c index ce0fb0ec9..88b7ed28a 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -437,8 +437,10 @@ GIT_INLINE(bool) iterator_has_started(git_iterator *iter, const char *path) GIT_INLINE(bool) iterator_has_ended(git_iterator *iter, const char *path) { - if (iter->end == NULL || iter->ended == true) + if (iter->end == NULL) return false; + else if (iter->ended) + return true; iter->ended = (iter->prefixcomp(path, iter->end) > 0); return iter->ended; diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c index ea2b37d10..e668caf44 100644 --- a/tests/repo/iterator.c +++ b/tests/repo/iterator.c @@ -16,6 +16,17 @@ void test_repo_iterator__cleanup(void) g_repo = NULL; } +static void assert_at_end(git_iterator *i, bool verbose) +{ + const git_index_entry *end; + int error = git_iterator_advance(&end, i); + + if (verbose && error != GIT_ITEROVER) + fprintf(stderr, "Expected end of iterator, got '%s'\n", end->path); + + cl_git_fail_with(GIT_ITEROVER, error); +} + static void expect_iterator_items( git_iterator *i, int expected_flat, @@ -57,6 +68,7 @@ static void expect_iterator_items( break; } + assert_at_end(i, v); cl_assert_equal_i(expected_flat, count); cl_git_pass(git_iterator_reset(i)); @@ -103,6 +115,7 @@ static void expect_iterator_items( break; } + assert_at_end(i, v); cl_assert_equal_i(expected_total, count); }