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

[BUG] git add -A --dry-run adds files to .git directory

From
Ggit.mexon@spamgourmet.com <git.mexon@spamgourmet.com>
Date
Oct 12, 2021, 14:55 UTC
Message-ID
<a2c0deed-fff3-6c1c-633f-af9dffea1e02@exon.name>

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

mat@charly:~$ git init repo mat@charly:~$ cat /dev/random | head -c 100000000 > repo/randomfile mat@charly:~$ git -C repo add -A -n mat@charly:~$ du -hs repo/.git

What did you expect to happen? (Expected behavior)
  76K    repo/.git
What happened instead? (Actual behavior)
  97M    repo/.git
What's different between what you expected and what actually happened?

Even though I specified -n on the command line to make a dry run, it still added the large file as an object.

Anything else you want to add:

This is counter-intuitive behaviour.  When the documentation says "Don't actually add the file(s)", it's reasonable to expect that this command will leave the repository state as it found it.  If there's a good reason why these files should be added to the .git directory, that behaviour should be made clear in the documentation, probably including the reason why that counter-intuitive behaviour is necessary.

This bit me due to a script that was using git add -A -n to detect if a repository had been locally modified.  While I do have alternative (actually better) ways to get this information, it wasn't an unreasonable command to use in the first place, and it caused a real issue in a production system.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.30.1 (Apple Git-130) cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64 compiler info: clang: 13.0.0 (clang-1300.0.29.3) libc info: no libc information available $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]
Next: René Scharfe
Message 1 of 5 in “[BUG] git add -A --dry-run adds files to .git directory”
  1. git.mexon@spamgourmet.comOct 12, 2021
  2. add: don't write objects with --dry-runRené Scharfe, Oct 12, 2021
  3. Junio C HamanoOct 12, 2021
  4. Ævar Arnfjörð BjarmasonOct 12, 2021
  5. Junio C HamanoOct 12, 2021

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.