Skip to content

Commit 359dfe0

Browse files
Vampiretnyblom
authored andcommitted
Add gitignore placeholders for empty directories in branches when using svn-branches and empty-dirs parameter
1 parent 955a9e7 commit 359dfe0

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/svn.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,9 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
823823
txn->deleteFile(path);
824824
checkParentNotEmpty(pool, key, path, fs_root, txn);
825825
recursiveDumpDir(txn, fs, fs_root, key, path, pool, revnum, rule, matchRules, ruledebug, false);
826+
if (CommandLineParser::instance()->contains("empty-dirs")) {
827+
addGitIgnoreOnBranch(pool, key, path, fs_root, txn);
828+
}
826829
}
827830
if (rule.annotate) {
828831
// create an annotated tag

test/empty-dirs.bats

+68
Original file line numberDiff line numberDiff line change
@@ -911,3 +911,71 @@ load 'common'
911911
assert git -C git-repo show master:dir-b/.gitignore
912912
assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" ''
913913
}
914+
915+
@test 'branching with svn-branches and empty-dirs parameter should put empty .gitignore files to empty directories' {
916+
svn mkdir --parents trunk/dir-a
917+
svn commit -m 'add trunk/dir-a'
918+
svn mkdir branches
919+
svn cp trunk branches/branch-a
920+
svn commit -m 'create branch-a'
921+
922+
cd "$TEST_TEMP_DIR"
923+
svn2git "$SVN_REPO" --empty-dirs --svn-branches --rules <(echo "
924+
create repository git-repo
925+
end repository
926+
927+
match /trunk/
928+
repository git-repo
929+
branch master
930+
end match
931+
932+
match /branches/$
933+
action recurse
934+
end match
935+
936+
match /branches/([^/]+)/
937+
repository git-repo
938+
branch \1
939+
end match
940+
")
941+
942+
assert git -C git-repo show master:dir-a/.gitignore
943+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
944+
assert git -C git-repo show branch-a:dir-a/.gitignore
945+
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" ''
946+
}
947+
948+
@test 'branching with svn-branches and empty-dirs parameter should put empty .gitignore files to empty directories (nested)' {
949+
svn mkdir project-a
950+
cd project-a
951+
svn mkdir --parents trunk/dir-a
952+
svn commit -m 'add trunk/dir-a'
953+
svn mkdir branches
954+
svn cp trunk branches/branch-a
955+
svn commit -m 'create branch-a'
956+
957+
cd "$TEST_TEMP_DIR"
958+
svn2git "$SVN_REPO" --empty-dirs --svn-branches --rules <(echo "
959+
create repository git-repo
960+
end repository
961+
962+
match /project-a/trunk/
963+
repository git-repo
964+
branch master
965+
end match
966+
967+
match /project-a/branches/([^/]+)/
968+
repository git-repo
969+
branch \1
970+
end match
971+
972+
match /project-a/(branches/)?$
973+
action recurse
974+
end match
975+
")
976+
977+
assert git -C git-repo show master:dir-a/.gitignore
978+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
979+
assert git -C git-repo show branch-a:dir-a/.gitignore
980+
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" ''
981+
}

0 commit comments

Comments
 (0)