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

Weird output of git status in pre-commit hook when providing a pathspec on commit

From
Michaël Fortin <fortinmike@gmail.com>
Date
Feb 3, 2015, 13:14 UTC
Message-ID
<80E24BA2-84FE-47FC-A5C0-D291E3C63BD5@gmail.com>
Hi all,
I'm seeing behavior that I *think* might be a bug in git (I'm running 2.2.2). At least I couldn't find anything about this anywhere, so here goes:
I'm trying to run git commands outside of the current working copy (e.g. inside another repo) from a pre-commit hook. However I'm encountering a very weird issue that occurs when a pathspec is provided when performing a commit.
More precisely, what I'm trying to do is check whether a repository beside the current repository is clean (no uncommitted changes) or not, from a pre-commit hook.
My repositories look like this on disk:
ContainerDirectory
|-- Repo1 (contains one untracked file)
|-- Repo2 (no uncommitted changes)
Repo1 has the following pre-commit hook:

#!/bin/bash git -C "../Repo2" status --porcelain

I then commit in Repo1 using the following (this is actually ran by a GUI, I have no control over the commands themselves):

git add --force -- MyNewFile git commit -m "My message" -o -- MyNewFile

This results in some very puzzling output. I would expect the hook to output nothing because Repo2 contains no changes. However, it returns the following:

D Repo2-File1.txt D Repo2-File2.txt D Repo2-File3.txt ?? Repo2-File1.txt ?? Repo2-File2.txt ?? Repo2-File3.txt

As you can see, the files are listed as both deleted and untracked, which makes no sense to me because there are in fact no uncommitted changes in that repo. There are only these three files in the repo. Removing the pathspec ("-- MyNewFile") from the commit command shows the expected output (nothing, because there are no changes in Repo2).
I have reproduced this behavior on OS X and Windows (with the latest git for Windows).
Can you explain what's going on?
Thanks in advance for any info!

Michaël Fortin www.irradiated.net

Next: Jeff King
Message 1 of 3 in “Weird output of git status in pre-commit hook when providing a pathspec on commit”
  1. Michaël FortinFeb 3, 2015
  2. Jeff KingFeb 3, 2015
  3. Michaël FortinFeb 4, 2015

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.