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

A bug in git-add with GIT_DIR?

From
Orgad Shaneh <orgads@gmail.com>
Date
Dec 20, 2018, 08:37 UTC
Message-ID
<CAGHpTBKyBgPURYfuZgVwnskGSy9L1+3WMrYuPmziQ7VcGDkMcA@mail.gmail.com>
Hi,

I played around with t5403-post-checkout-hook, and noticed that its state is not exactly what I'd expect it to be.

The test setup is: echo Data for commit0. >a && echo Data for commit0. >b && git update-index --add a && git update-index --add b && tree0=$(git write-tree) && commit0=$(echo setup | git commit-tree $tree0) && git update-ref refs/heads/master $commit0 && git clone ./. clone1 && git clone ./. clone2 && GIT_DIR=clone2/.git git branch new2 && echo Data for commit1. >clone2/b && GIT_DIR=clone2/.git git add clone2/b && GIT_DIR=clone2/.git git commit -m new2

Now, the line before the last one executes git add clone2/b with GIT_DIR set.

I'd expect that to add b inside clone2, but instead it adds an inexistent clone2/clone2/b, and if I stop at this line, then the status shows:

On branch master Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
        new file:   clone2/b
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   b
        deleted:    clone2/b

Is this the intended behavior? It looks like that's not what the test meant to do anyway...

And if I change it to (cd clone2 && git add b), then the commits look reasonable, but step 6 fails.

- Orgad
Next: Jeff King
Message 1 of 3 in “A bug in git-add with GIT_DIR?”
  1. Orgad ShanehDec 20, 2018
  2. Jeff KingDec 20, 2018
  3. Orgad ShanehDec 20, 2018

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.