git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] assertion failure in builtin-mv.c with "git mv -k"

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jan 14, 2009, 13:20 UTC
Message-ID
<vpqwscy81o8.fsf@bauges.imag.fr>
Hi,
Just found a bug in builtin-mv.c. Here's a script to reproduce:

mkdir git cd git git init touch controled git add controled && git commit -m "init" touch foo1 foo2 mkdir dir git mv -k foo* dir/

The output is the following:
Initialized empty Git repository in /tmp/git/.git/
[master (root-commit)]: created 694563b: "init"
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 controled
git: builtin-mv.c:216: cmd_mv: Assertion `pos >= 0' failed.
./bug.sh: line 10: 12919 Aborted                 git mv -k foo* dir/

Apparently, this happens when using "git mv -k" with more than one unversionned file. The code ignores the first one, but still goes through this

	for (i = 0; i < argc; i++) {
		const char *src = source[i], *dst = destination[i];
		enum update_mode mode = modes[i];
		int pos;
		if (show_only || verbose)
			printf("Renaming %s to %s\n", src, dst);
		if (!show_only && mode != INDEX &&
				rename(src, dst) < 0 && !ignore_errors)
			die ("renaming %s failed: %s", src, strerror(errno));
		if (mode == WORKING_DIRECTORY)
			continue;
		pos = cache_name_pos(src, strlen(src));
		assert(pos >= 0); /* <----- this is the one */
		if (!show_only)
			rename_cache_entry_at(pos, dst);
	}

for the second, and it crashes on the assertion (gdb says "pos" here is an unversionned file name).

If anyone has time to fix this ...
Thanks,
-- 
Matthieu
Next: Michael J Gruber
Message 1 of 14 in “[BUG] assertion failure in builtin-mv.c with "git mv -k"”
  1. Matthieu MoyJan 14, 2009
  2. Michael J GruberJan 14, 2009
  3. Johannes SchindelinJan 14, 2009
  4. Michael J GruberJan 14, 2009
  5. Jeff KingJan 14, 2009
  6. Junio C HamanoJan 14, 2009
  7. Michael J GruberJan 15, 2009
  8. Junio C HamanoJan 15, 2009
  9. Matthieu MoyJan 16, 2009
  10. 0/3 Add test cases for "git mv -k" and fix a known breakage.Michael J Gruber, Jan 14, 2009
  11. 1/3 add test cases for "git mv -k"Michael J Gruber, Jan 14, 2009
  12. 2/3 fix handling of multiple untracked files for git mv -kMichael J Gruber, Jan 14, 2009
  13. 3/3 mark fixed breakage as expect pass for "git mv -k" multiple filesMichael J Gruber, Jan 14, 2009
  14. fix handling of multiple untracked files for git mv -kMichael J Gruber, Jan 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.