Skip to content

Commit

Permalink
Merge branch 'jk/rm-removed-paths'
Browse files Browse the repository at this point in the history
A handful of test cases and a corner case bugfix for "git rm".

* jk/rm-removed-paths:
  t3600: document failure of rm across symbolic links
  t3600: test behavior of reverse-d/f conflict
  rm: do not complain about d/f conflicts during deletion
  • Loading branch information
Junio C Hamano committed Apr 7, 2013
2 parents e65cdde + 03415ca commit 0f3d66c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int check_local_mod(unsigned char *head, int index_only)
ce = active_cache[pos];

if (lstat(ce->name, &st) < 0) {
if (errno != ENOENT)
if (errno != ENOENT && errno != ENOTDIR)
warning("'%s': %s", ce->name, strerror(errno));
/* It already vanished from the working tree */
continue;
Expand Down
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ int remove_path(const char *name)
{
char *slash;

if (unlink(name) && errno != ENOENT)
if (unlink(name) && errno != ENOENT && errno != ENOTDIR)
return -1;

slash = strrchr(name, '/');
Expand Down
65 changes: 65 additions & 0 deletions t/t3600-rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,69 @@ test_expect_success 'rm of a populated nested submodule with a nested .git direc
rm -rf submod
'

test_expect_success 'rm of d/f when d has become a non-directory' '
rm -rf d &&
mkdir d &&
>d/f &&
git add d &&
rm -rf d &&
>d &&
git rm d/f &&
test_must_fail git rev-parse --verify :d/f &&
test_path_is_file d
'

test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
rm -rf d &&
mkdir d &&
>d/f &&
git add d &&
rm -rf d &&
ln -s nonexistent d &&
git rm d/f &&
test_must_fail git rev-parse --verify :d/f &&
test -h d &&
test_path_is_missing d
'

test_expect_success 'rm of file when it has become a directory' '
rm -rf d &&
>d &&
git add d &&
rm -f d &&
mkdir d &&
>d/f &&
test_must_fail git rm d &&
git rev-parse --verify :d &&
test_path_is_file d/f
'

test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
rm -rf d e &&
mkdir e &&
echo content >e/f &&
ln -s e d &&
git add -A e d &&
git commit -m "symlink d to e, e/f exists" &&
test_must_fail git rm d/f &&
git rev-parse --verify :d &&
git rev-parse --verify :e/f &&
test -h d &&
test_path_is_file e/f
'

test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
rm -rf d e &&
mkdir d &&
echo content >d/f &&
git add -A e d &&
git commit -m "d/f exists" &&
mv d e &&
ln -s e d &&
test_must_fail git rm d/f &&
git rev-parse --verify :d/f &&
test -h d &&
test_path_is_file e/f
'

test_done

0 comments on commit 0f3d66c

Please sign in to comment.