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

Re: git rm bug

From
Duy Nguyen <pclouds@gmail.com>
Date
Jun 6, 2018, 19:54 UTC
Message-ID
<CACsJy8CpsF8rtiJVtLK4d=7RdtPBy5QRy7XURFvpaWtQCynJkA@mail.gmail.com>
In-Reply-To
<1528313557.2662346.1398855328.3E0F8023@webmail.messagingengine.com>

On Wed, Jun 6, 2018 at 9:32 PM, Thomas Fischer <thomasfischer@fastmail.com> wrote:

> OVERVIEW
>
> "git rm" will remove more files than specified. This is either a bug or undocumented behavior (not in the man pages).

The behavior is intended, with a question mark. This change is introduced in d9b814cc97 (Add builtin "git rm" command - 2006-05-19). I quote the relevant paragraph from that commit

    The other question is what to do with leading directories. The old "git
    rm" script didn't do anything, which is somewhat inconsistent. This one
    will actually clean up directories that have become empty as a result of
    removing the last file, but maybe we want to have a flag to decide the
    behaviour?

To me we definitely should document this (patches welcome!) then maybe revisit this "have a flag to decide the behavior" question from 12 years ago.

Show 44 quoted lines
> SETUP
>
> 1. In a git repository, create an empty directory OR a chain of empty directories
>
> $ mkdir -p path/to/some/
>
> 2. Create a file in the deepest directory and add it to tracking
>
> $ touch path/to/some/file
> $ git add path/to/some/file
> $ git commit -m 'add path/to/some/file'
>
> THE BUG
>
> Run 'git rm' on the tracked file.
>
> EXPECTED BEHAVIOR
>
> $ git rm path/to/some/file
> rm 'path/to/some/file'
> $ ls path
> to/
> $ ls path/to
> some/
>
> Note that path/, path/to/, and path/to/some/ still exist.
>
> ACTUAL BEHAVIOR
>
> $ git rm path/to/some/file
> rm 'path/to/some/file'
> $ ls path
> ls: cannot access 'path': No such file or directory
>
> The entire chain of empty directories is removed, despite the fact the git outputs only "rm 'path/to/some/file'".
>
> This ONLY occurs when all the directories in the chain are empty after the tracked file has been removed.
>
> This behavior is NOT documented in the man pages.
>
> I propose that 'rmdir' statements are added to 'git rm' output, or that the man pages be updated to reflect this behavior.
>
> Best,
> Thomas Fischer
-- 
Duy
Previous: Ævar Arnfjörð Bjarmason
Message 11 of 11 in “git rm bug”
  1. Thomas FischerJun 6, 2018
  2. Robert P. J. DayJun 6, 2018
  3. Thomas FischerJun 6, 2018
  4. Robert P. J. DayJun 6, 2018
  5. Todd ZullingerJun 6, 2018
  6. Jeff KingJun 6, 2018
  7. Timothy RiceJun 6, 2018
  8. Robert P. J. DayJun 6, 2018
  9. Ævar Arnfjörð BjarmasonJun 6, 2018
  10. Ævar Arnfjörð BjarmasonJun 6, 2018
  11. Duy NguyenJun 6, 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.