]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/mv: convert assert(3p) into `BUG()`
authorPatrick Steinhardt <ps@pks.im>
Wed, 30 Apr 2025 12:44:58 +0000 (14:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Apr 2025 22:22:04 +0000 (15:22 -0700)
The use of asserts is discouraged in our codebase because they lead to
different behaviour depending on how Git is built. When being unsure
enough whether a condition always holds so that one adds the assert,
then the assert should probably trigger regardless of how Git is being
built.

Drop the call to assert(3p) in git-mv(1) and instead use `BUG()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c

index c17e14cee6e9b2593435304c7dacacd684801571..4b4e1fce2e28bf462da667bf754d2ad035e7e9b8 100644 (file)
@@ -560,7 +560,8 @@ remove_entry:
                        continue;
 
                pos = index_name_pos(the_repository->index, src, strlen(src));
-               assert(pos >= 0);
+               if (pos < 0)
+                       BUG("could not find source in index: '%s'", src);
                if (!(mode & SPARSE) && !lstat(src, &st))
                        sparse_and_dirty = ie_modified(the_repository->index,
                                                       the_repository->index->cache[pos],