Skip to content

Commit

Permalink
Merge branch 'jl/submodule-rm'
Browse files Browse the repository at this point in the history
Finishing touches to "git rm $submodule" that removes the working
tree of a submodule.

* jl/submodule-rm:
  Teach rm to remove submodules when given with a trailing '/'
  • Loading branch information
Junio C Hamano committed Nov 29, 2012
2 parents 36ea7ce + 53e4c5d commit 276d709
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (read_cache() < 0)
die(_("index file corrupt"));

/*
* Drop trailing directory separators from directories so we'll find
* submodules in the index.
*/
for (i = 0; i < argc; i++) {
size_t pathlen = strlen(argv[i]);
if (pathlen && is_dir_sep(argv[i][pathlen - 1]) &&
is_directory(argv[i])) {
do {
pathlen--;
} while (pathlen && is_dir_sep(argv[i][pathlen - 1]));
argv[i] = xmemdupz(argv[i], pathlen);
}
}

pathspec = get_pathspec(prefix, argv);
refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);

Expand Down
17 changes: 17 additions & 0 deletions t/t3600-rm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,23 @@ test_expect_success 'rm removes work tree of unmodified submodules' '
test_cmp expect actual
'

test_expect_success 'rm removes a submodule with a trailing /' '
git reset --hard &&
git submodule update &&
git rm submod/ &&
test ! -d submod &&
git status -s -uno --ignore-submodules=none > actual &&
test_cmp expect actual
'

test_expect_success 'rm fails when given a file with a trailing /' '
test_must_fail git rm empty/
'

test_expect_success 'rm succeeds when given a directory with a trailing /' '
git rm -r frotz/
'

test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
git reset --hard &&
git submodule update &&
Expand Down

0 comments on commit 276d709

Please sign in to comment.