Skip to content

Commit caba91c

Browse files
newrengitster
authored andcommitted
fast-rebase: change assert() to BUG()
assert() can succinctly document expectations for the code, and do so in a way that may be useful to future folks trying to refactor the code and change basic assumptions; it allows them to more quickly find some places where their violations of previous assumptions trips things up. Unfortunately, assert() can surround a function call with important side-effects, which is a huge mistake since some users will compile with assertions disabled. I've had to debug such mistakes before in other codebases, so I should know better. Luckily, this was only in test code, but it's still very embarrassing. Change an assert() to an if (...) BUG (...). Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb80333 commit caba91c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

t/helper/test-fast-rebase.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ int cmd__fast_rebase(int argc, const char **argv)
124124
assert(oideq(&onto->object.oid, &head));
125125

126126
hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
127-
assert(repo_read_index(the_repository) >= 0);
127+
if (repo_read_index(the_repository) < 0)
128+
BUG("Could not read index");
128129

129130
repo_init_revisions(the_repository, &revs, NULL);
130131
revs.verbose_header = 1;

0 commit comments

Comments
 (0)