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

[PATCH] Remove empty directories in recursive merge

From
Alex Riesen <raa.lkml@gmail.com>
Date
Sep 25, 2008, 20:12 UTC
Message-ID
<20080925201245.GB3959@blimp.localhost>
In-Reply-To
<87k5d1v71l.fsf@cup.kalibalik.dk>

The code was actually supposed to do that, but was accidentally broken. Noticed by Anders Melchiorsen.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Anders Melchiorsen, Wed, Sep 24, 2008 18:32:22 +0200:
> 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.
Ach, an old bug. Thanks for reminding!
 builtin-merge-recursive.c  |    4 +---
 t/t3030-merge-recursive.sh |   11 +++++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c
index dfb363e..a29b47f 100644
--- a/builtin-merge-recursive.c
+++ b/builtin-merge-recursive.c
@@ -444,10 +444,8 @@ static int remove_file(int clean, const char *path, int no_wd)
 			return -1;
 	}
 	if (update_working_directory) {
-		unlink(path);
-		if (errno != ENOENT || errno != EISDIR)
+		if (remove_path(path) && errno != ENOENT)
 			return -1;
-		remove_path(path);
 	}
 	return 0;
 }
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index de0cdb1..0de613d 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -535,4 +535,15 @@ test_expect_success 'reset and bind merge' '
 
 '
 
+test_expect_success 'merge removes empty directories' '
+
+	git reset --hard master &&
+	git checkout -b rm &&
+	git rm d/e &&
+	git commit -mremoved-d/e &&
+	git checkout master &&
+	git merge -s recursive rm &&
+	test_must_fail test -d d
+'
+
 test_done
-- 
1.6.0.2.328.g14651
Previous: Anders MelchiorsenNext: Alex Riesen
Message 2 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.