From: Jonathan Nieder Date: Thu, 27 Jan 2011 06:07:49 +0000 (-0600) Subject: fast-import: treat filemodify with empty tree as delete X-Git-Tag: ko-maint~2^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8fe533f686e20852fa9bd2df2755faed7c7bcdcc;p=git.git fast-import: treat filemodify with empty tree as delete Normal git processes do not allow one to build a tree with an empty subtree entry without trying hard at it. This is in keeping with the general UI philosophy: git tracks content, not empty directories. v1.7.3-rc0~75^2 (2010-06-30) changed that by making it easy to include an empty subtree in fast-import's active commit: M 040000 4b825dc642cb6eb9a060e54bf8d69288fbee4904 subdir One can trigger this by reading an empty tree (for example, the tree corresponding to an empty root commit) and trying to move it to a subtree. It is better and more closely analogous to 'git read-tree --prefix' to treat such commands as requests to remove the subtree. Noticed-by: David Barr Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- diff --git a/fast-import.c b/fast-import.c index ad6843a8b..cd9310d1e 100644 --- a/fast-import.c +++ b/fast-import.c @@ -2163,6 +2163,12 @@ static void file_change_m(struct branch *b) p = uq.buf; } + /* Git does not track empty, non-toplevel directories. */ + if (S_ISDIR(mode) && !memcmp(sha1, EMPTY_TREE_SHA1_BIN, 20) && *p) { + tree_content_remove(&b->branch_tree, p, NULL); + return; + } + if (S_ISGITLINK(mode)) { if (inline_data) die("Git links cannot be specified 'inline': %s", diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 50d5913cc..8487734ad 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -817,6 +817,48 @@ test_expect_success \ git diff-tree -C --find-copies-harder -r N4^ N4 >actual && compare_diff_raw expect actual' +test_expect_success \ + 'N: delete directory by copying' \ + 'cat >expect <<-\EOF && + OBJID + :100644 000000 OBJID OBJID D foo/bar/qux + OBJID + :000000 100644 OBJID OBJID A foo/bar/baz + :000000 100644 OBJID OBJID A foo/bar/qux + EOF + empty_tree=$(git mktree input <<-INPUT_END && + commit refs/heads/N-delete + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data < $GIT_COMMITTER_DATE + data <actual && + test_cmp expect actual' + test_expect_success \ 'N: modify copied tree' \ 'cat >expect <<-\EOF &&