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

Re: [BUG] mv: can trigger assertion failure with three parameters (builtin/mv.c:481)

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 5, 2024, 18:52 UTC
Message-ID
<xmqqil47obnw.fsf@gitster.g>
In-Reply-To
<d1f739fe-b28e-451f-9e01-3d2e24a0fe0d@app.fastmail.com>
"Kristoffer Haugsbakk" <code@khaugsbakk.name> writes:
Show 8 quoted lines
> You can trigger an assertion by giving these arguments to `git mv`:
>
>     <dir>/file <dir> <other dir>
> ...
>> What did you expect to happen? (Expected behavior)
>
> A normal error message if the command is nonsensical (I don’t know; that’s
> not the point). Also `.git/index.lock` to be cleaned up.
Good find.

Not just that, but when the command fails in the middle like this, it leaves the working tree in a half-updated state, i.e.

> ./bin-wrappers/git -C $dir mv $dir/a/a.txt $dir/a $dir/b

will first move a/a.txt to b/a.txt, then try to move a (actually, all contents of it, including a/a.txt) to b/a and finds that "the command is nonsensical" and aborts, and by that time, there is no a/a.txt (i.e. the working tree has been modified). The failure should be made atomic, just like "git switch" to another branch may stop _without_ touching anything in the working tree when it may have to fail (e.g., due to a file being dirty).

Thanks for reporting, Kristoffer.
Any takers?
$ git shortlog --since=3.years -s -n -e --no-merges v2.43.0 builtin/mv.c
    15	Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
    10	Elijah Newren <newren@gmail.com>
     5	Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     2	Junio C Hamano <gitster@pobox.com>
     1	Andrzej Hunt <ajrhunt@google.com>
     1	Calvin Wan <calvinwan@google.com>
     1	Derrick Stolee <stolee@gmail.com>
     1	Sebastian Thiel <sebastian.thiel@icloud.com>
     1	Torsten Bögershausen <tboegi@web.de>
Previous: Kristoffer HaugsbakkNext: Dragan Simic
Message 2 of 10 in “[BUG] mv: can trigger assertion failure with three parameters (builtin/mv.c:481)”
  1. Kristoffer HaugsbakkJan 5, 2024
  2. Junio C HamanoJan 5, 2024
  3. Dragan SimicJan 5, 2024
  4. Kristoffer HaugsbakkFeb 18, 2024
  5. t7001: add failure test which triggers assertionkristofferhaugsbakk@fastmail.com, Oct 20, 2024
  6. Taylor BlauOct 21, 2024
  7. Kristoffer HaugsbakkOct 21, 2024
  8. Taylor BlauOct 21, 2024
  9. t7001: add failure test which triggers assertionkristofferhaugsbakk@fastmail.com, Oct 22, 2024
  10. Taylor BlauOct 23, 2024

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.