Skip to content

Commit

Permalink
Demonstrate breakage: checkout overwrites untracked symlink with dire…
Browse files Browse the repository at this point in the history
…ctory

This adds tests where an untracked file and an untracked symlink are in the
way where a directory should be created by 'git checkout'. Commit b1735b1
(do not overwrite files in leading path, 2010-12-14) fixed the case where
a file is in the way, but the untracked symlink is still removed silently.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Feb 15, 2011
1 parent 7ed863a commit 2fe26b7
Showing 1 changed file with 50 additions and 0 deletions.
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

0 comments on commit 2fe26b7

Please sign in to comment.