Thread (1 message) 1 message, 1 author, 2016-06-15
DORMANTno replies

[PATCH] git-apply: do not lose cwd when run from a subdirectory.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:55
Subsystem: the rest · Maintainer: Linus Torvalds

When a patch modifies (not deletes) the last file in a
directory, because we treat a modification just as deletion
followed by creation, and deleting the last file in a directory
automatically rmdir(2)'s that directory, we ended up removing
the directory, which can potentially be the cwd, and then
recreating the same directory to create the patch result.

Avoid the rmdir step when remove_file() is called only because
we are replacing it with the result by later calling
create_file().

Signed-off-by: Junio C Hamano <redacted>
---

 * This is not related to the previous patch, but the updated
   test trigeers it ;-).

 builtin-apply.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 20fb5bd..6153791 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2243,7 +2243,7 @@ static void patch_stats(struct patch *patch)
 	}
 }
 
-static void remove_file(struct patch *patch)
+static void remove_file(struct patch *patch, int rmdir_empty)
 {
 	if (write_index) {
 		if (remove_file_from_cache(patch->old_name) < 0)
@@ -2251,7 +2251,7 @@ static void remove_file(struct patch *patch)
 		cache_tree_invalidate_path(active_cache_tree, patch->old_name);
 	}
 	if (!cached) {
-		if (!unlink(patch->old_name)) {
+		if (!unlink(patch->old_name) && rmdir_empty) {
 			char *name = xstrdup(patch->old_name);
 			char *end = strrchr(name, '/');
 			while (end) {
-- 
1.5.0.1.555.g13b30
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help