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

[BUG] git merge does not prune empty directories

From
AMAnders Melchiorsen <mail@cup.kalibalik.dk>
Date
Sep 24, 2008, 16:32 UTC
Message-ID
<87k5d1v71l.fsf@cup.kalibalik.dk>

I got an empty directory left over today, and have reduced the problem to this sequence. If I leave out the second add (so the merge is a fast forward), the directory is removed as I would expect.

This is with Git 1.6.0.2.
    Anders
and@dylle:~$ mkdir repo ; cd repo
and@dylle:~/repo$ git init
Initialized empty Git repository in /home/and/repo/.git/
and@dylle:~/repo$ mkdir a ; date >a/b ; git add a/b ; git commit -m'Add 1'
Created initial commit 72194c7: Add 1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a/b
and@dylle:~/repo$ git checkout -b other
Switched to a new branch "other"
and@dylle:~/repo$ git rm a/b ; git commit -m'Remove 1'
rm 'a/b'
Created commit 9c0282c: Remove 1
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 100644 a/b
and@dylle:~/repo$ git checkout master
Switched to branch "master"
and@dylle:~/repo$ date >c ; git add c ; git commit -m'Add 2'
Created commit 39d60d4: Add 2
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 c
and@dylle:~/repo$ git merge other
Removed a/b
Merge made by recursive.
 a/b |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 100644 a/b
and@dylle:~/repo$ rmdir a
and@dylle:~/repo$ rmdir a
rmdir: failed to remove `a': No such file or directory
Next: Alex Riesen
Message 1 of 10 in “[BUG] git merge does not prune empty directories”
  1. Anders MelchiorsenSep 24, 2008
  2. Remove empty directories in recursive mergeAlex Riesen, Sep 25, 2008
  3. Cleanup remove_pathAlex Riesen, Sep 25, 2008
  4. Fix memleak and the implementation of remove_file in builtin-rm.cAlex Riesen, Sep 25, 2008
  5. Shawn O. PearceSep 26, 2008
  6. Add remove_path: a function to remove as much as possible of a pathAlex Riesen, Sep 26, 2008
  7. Use remove_path from dir.c instead of own implementationAlex Riesen, Sep 26, 2008
  8. Alex RiesenSep 25, 2008
  9. Shawn O. PearceSep 26, 2008
  10. Johannes SixtSep 26, 2008

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.