Skip to content

Commit 5ce3258

Browse files
committed
Merge branch 'jn/fast-import-empty-tree-removal' into maint
* jn/fast-import-empty-tree-removal: fast-import: treat filemodify with empty tree as delete
2 parents 4ac5356 + 8fe533f commit 5ce3258

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

fast-import.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,12 @@ static void file_change_m(struct branch *b)
21662166
p = uq.buf;
21672167
}
21682168

2169+
/* Git does not track empty, non-toplevel directories. */
2170+
if (S_ISDIR(mode) && !memcmp(sha1, EMPTY_TREE_SHA1_BIN, 20) && *p) {
2171+
tree_content_remove(&b->branch_tree, p, NULL);
2172+
return;
2173+
}
2174+
21692175
if (S_ISGITLINK(mode)) {
21702176
if (inline_data)
21712177
die("Git links cannot be specified 'inline': %s",

t/t9300-fast-import.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,48 @@ test_expect_success \
874874
git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
875875
compare_diff_raw expect actual'
876876

877+
test_expect_success \
878+
'N: delete directory by copying' \
879+
'cat >expect <<-\EOF &&
880+
OBJID
881+
:100644 000000 OBJID OBJID D foo/bar/qux
882+
OBJID
883+
:000000 100644 OBJID OBJID A foo/bar/baz
884+
:000000 100644 OBJID OBJID A foo/bar/qux
885+
EOF
886+
empty_tree=$(git mktree </dev/null) &&
887+
cat >input <<-INPUT_END &&
888+
commit refs/heads/N-delete
889+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
890+
data <<COMMIT
891+
collect data to be deleted
892+
COMMIT
893+
894+
deleteall
895+
M 100644 inline foo/bar/baz
896+
data <<DATA_END
897+
hello
898+
DATA_END
899+
C "foo/bar/baz" "foo/bar/qux"
900+
C "foo/bar/baz" "foo/bar/quux/1"
901+
C "foo/bar/baz" "foo/bar/quuux"
902+
M 040000 $empty_tree foo/bar/quux
903+
M 040000 $empty_tree foo/bar/quuux
904+
905+
commit refs/heads/N-delete
906+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
907+
data <<COMMIT
908+
delete subdirectory
909+
COMMIT
910+
911+
M 040000 $empty_tree foo/bar/qux
912+
INPUT_END
913+
git fast-import <input &&
914+
git rev-list N-delete |
915+
git diff-tree -r --stdin --root --always |
916+
sed -e "s/$_x40/OBJID/g" >actual &&
917+
test_cmp expect actual'
918+
877919
test_expect_success \
878920
'N: modify copied tree' \
879921
'cat >expect <<-\EOF &&

0 commit comments

Comments
 (0)