@matheusbsbs / matheus-bagliano / commits / 16a4c6176a
Fork 0

read-tree -m -u: avoid getting confused by intermediate symlinks.

When switching from a branch with both x86_64/boot/Makefile and i386/boot/Makefile to another branch that has x86_64/boot as a symlink pointing at ../i386/boot, the code incorrectly removed i386/boot/Makefile. This was because we first removed everything under x86_64/boot to make room to create a symbolic link x86_64/boot, then removed x86_64/boot/Makefile which no longer exists but now is pointing at i386/boot/Makefile, thanks to the symlink we just created. This fixes it by using the has_symlink_leading_path() function introduced previously for git-apply in the checkout codepath. Earlier, "git checkout" was broken in t4122 test due to this bug, and the test had an extra "git reset --hard" as a workaround, which is removed because it is not needed anymore. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 10, 2007 at 23:44 UTC 16a4c6176ad096881d0021f1a922fbcc2835f799
2 files changed +10 -5
t/t4122-apply-symlink-inside.sh
-1
@@ -34,7 +34,6 @@ test_expect_success setup '
34 test_expect_success apply '
35
36 git checkout test &&
37 - git reset --hard && #### checkout seems to be buggy
37 git diff --exit-code test &&
38 git diff --exit-code --cached test &&
39 git apply --index test.patch
unpack-trees.c
+10 -4
@@ -264,10 +264,12 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
264 * directories, in case this unlink is the removal of the
265 * last entry in the directory -- empty directories are removed.
266 */
267 -static void unlink_entry(char *name)
267 +static void unlink_entry(char *name, char *last_symlink)
268 {
269 char *cp, *prev;
270
271 + if (has_symlink_leading_path(name, last_symlink))
272 + return;
273 if (unlink(name))
274 return;
275 prev = NULL;
@@ -291,11 +293,12 @@ static void unlink_entry(char *name)
293
294 static struct checkout state;
295 static void check_updates(struct cache_entry **src, int nr,
294 - struct unpack_trees_options *o)
296 + struct unpack_trees_options *o)
297 {
298 unsigned short mask = htons(CE_UPDATE);
299 unsigned cnt = 0, total = 0;
300 struct progress progress;
301 + char last_symlink[PATH_MAX];
302
303 if (o->update && o->verbose_update) {
304 for (total = cnt = 0; cnt < nr; cnt++) {
@@ -309,6 +312,7 @@ static void check_updates(struct cache_entry **src, int nr,
312 cnt = 0;
313 }
314
315 + *last_symlink = '\0';
316 while (nr--) {
317 struct cache_entry *ce = *src++;
318
@@ -317,13 +321,15 @@ static void check_updates(struct cache_entry **src, int nr,
321 display_progress(&progress, ++cnt);
322 if (!ce->ce_mode) {
323 if (o->update)
320 - unlink_entry(ce->name);
324 + unlink_entry(ce->name, last_symlink);
325 continue;
326 }
327 if (ce->ce_flags & mask) {
328 ce->ce_flags &= ~mask;
325 - if (o->update)
329 + if (o->update) {
330 checkout_entry(ce, &state, NULL);
331 + *last_symlink = '\0';
332 + }
333 }
334 }
335 if (total)