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

RE: "git commit" fails due to spurious file in index

From
RIRobert Irelan <rirelan@epic.com>
Date
Mar 5, 2013, 15:30 UTC
Message-ID
<2D9BD788B02ABA478C57929170AF952B7637B5@EXCH-MBX-3.epic.com>
In-Reply-To
<87y5e2op9p.fsf@pctrast.inf.ethz.ch>
Yes, you're correct, it was a bug in my pre-commit hook. Thanks!
For posterity, the issue is that I had the following line:
    git diff -z --cached --name-only | egrep -z '\.(pl|pm|t)$' | \
            while read -d'' -r f; do ...

In Bash, when `read` is passed the `-d` option with a zero-length string argument, read will split on null characters (`'\0'`). However, I did not put a space between the `-d` option and the argument, so it took the `-` in the next argument `-r` as the delimiter. My commit includes Perl files with `-` characters in the name, which I had not previously committed to this repo, which is why I only ran into the problem now. I fixed it by changing the read command to `read -r -d '' f`, which now has the crucial space between -d and its argument, making the zero-length string a separate argument.

Robert Irelan | Server Systems | Epic | (608) 271-9000
-----Original Message-----
From: Thomas Rast [mailto:trast@student.ethz.ch] 
Sent: Monday, March 04, 2013 2:59 PM
To: Robert Irelan
Cc: git@vger.kernel.org
Subject: Re: "git commit" fails due to spurious file in index
Robert Irelan <rirelan@epic.com> writes:
Show 11 quoted lines
> Now, when I run 'git add admin_script/setup' to add the new directory 
> to the repo and then try to commit, I receive the following message:
>
>     $ git commit
>     mv: cannot stat `admin_scripts/setup/2012/setup': No such file or 
> directory
>
> The error message is correct in that `admin_scripts/setup/2012/setup` 
> does not exist, either as a file or as a directory. However, I'm not 
> attempting to add this path at all. Using grep, I've confirmed that 
> the only place this path appears in any of my files is in `.git/index`.
To me that sounds like the message comes from a commit hook.  Can you check if you have anything in .git/hooks/, especially pre-commit?
There really isn't any other good reason why 'git commit' would call 'mv' (plain mv, not git!).

-- Thomas Rast trast@{inf,student}.ethz.ch

Previous: Thomas RastNext: Torsten Bögershausen
Message 3 of 5 in “"git commit" fails due to spurious file in index”
  1. Robert IrelanMar 4, 2013
  2. Thomas RastMar 4, 2013
  3. Robert IrelanMar 5, 2013
  4. Torsten BögershausenMar 5, 2013
  5. Robert IrelanMar 5, 2013

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.