Skip to content

Commit

Permalink
Merge branch 'js/checkout-untracked-symlink' into maint
Browse files Browse the repository at this point in the history
* js/checkout-untracked-symlink:
  do not overwrite untracked symlinks
  Demonstrate breakage: checkout overwrites untracked symlink with directory
  • Loading branch information
Junio C Hamano committed Apr 1, 2011
2 parents d12d8ec + 1d718a5 commit 46a1f07
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion symlinks.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ int check_leading_path(const char *name, int len)
int flags;
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
if (flags & (FL_SYMLINK|FL_NOENT))
if (flags & FL_NOENT)
return 0;
else if (flags & FL_DIR)
return -1;
Expand Down
50 changes: 50 additions & 0 deletions t/t2021-checkout-overwrite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

test_description='checkout must not overwrite an untracked objects'
. ./test-lib.sh

test_expect_success 'setup' '
mkdir -p a/b/c &&
>a/b/c/d &&
git add -A &&
git commit -m base &&
git tag start
'

test_expect_success 'create a commit where dir a/b changed to file' '
git checkout -b file &&
rm -rf a/b &&
>a/b &&
git add -A &&
git commit -m "dir to file"
'

test_expect_success 'checkout commit with dir must not remove untracked a/b' '
git rm --cached a/b &&
git commit -m "un-track the file" &&
test_must_fail git checkout start &&
test -f a/b
'

test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink' '
rm -rf a/b && # cleanup if previous test failed
git checkout -f -b symlink start &&
rm -rf a/b &&
ln -s foo a/b &&
git add -A &&
git commit -m "dir to symlink"
'

test_expect_failure SYMLINKS 'checkout commit with dir must not remove untracked a/b' '
git rm --cached a/b &&
git commit -m "un-track the symlink" &&
test_must_fail git checkout start &&
test -h a/b
'

test_done
14 changes: 11 additions & 3 deletions t/t6035-merge-dir-to-symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink'
git commit -m "dir to symlink"
'

test_expect_success SYMLINKS 'keep a/b-2/c/d across checkout' '
test_expect_success SYMLINKS 'checkout does not clobber untracked symlink' '
git checkout HEAD^0 &&
git reset --hard master &&
git rm --cached a/b &&
git commit -m "untracked symlink remains" &&
git checkout start^0 &&
test -f a/b-2/c/d
test_must_fail git checkout start^0
'

test_expect_success SYMLINKS 'a/b-2/c/d is kept when clobbering symlink b' '
git checkout HEAD^0 &&
git reset --hard master &&
git rm --cached a/b &&
git commit -m "untracked symlink remains" &&
git checkout -f start^0 &&
test -f a/b-2/c/d
'

test_expect_success SYMLINKS 'checkout should not have deleted a/b-2/c/d' '
Expand Down

0 comments on commit 46a1f07

Please sign in to comment.