Skip to content

Commit fcb62af

Browse files
Vampiretnyblom
authored andcommitted
Do not replace filled gitignore files with empty ones
1 parent 359dfe0 commit fcb62af

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

Diff for: src/svn.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,19 @@ int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path,
11021102
if (apr_hash_count(entries)!=0) {
11031103
return EXIT_FAILURE;
11041104
}
1105+
1106+
// if svn-ignore should have added a .gitignore file, do not overwrite it with an empty one
1107+
// if svn:ignore could not be determined, stay safe and do not overwrite the .gitignore file
1108+
// even if then an empty directory might be missing
1109+
QString svnignore;
1110+
if (CommandLineParser::instance()->contains("svn-ignore")) {
1111+
if (fetchIgnoreProps(&svnignore, pool, key, fs_root) != EXIT_SUCCESS) {
1112+
qWarning() << "Error fetching svn-properties (" << key << ")";
1113+
return EXIT_FAILURE;
1114+
} else if (!svnignore.isNull()) {
1115+
return EXIT_FAILURE;
1116+
}
1117+
}
11051118
}
11061119

11071120
// Add gitignore-File

Diff for: test/empty-dirs.bats

+66
Original file line numberDiff line numberDiff line change
@@ -979,3 +979,69 @@ load 'common'
979979
assert git -C git-repo show branch-a:dir-a/.gitignore
980980
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" ''
981981
}
982+
983+
@test 'branching with svn-ignore, svn-branches and empty-dirs parameter should not replace filled .gitignore files with empty ones' {
984+
svn mkdir --parents trunk/dir-a
985+
svn propset svn:ignore 'ignore-a' trunk/dir-a
986+
svn commit -m 'add trunk/dir-a'
987+
svn mkdir branches
988+
svn cp trunk branches/branch-a
989+
svn commit -m 'create branch-a'
990+
991+
cd "$TEST_TEMP_DIR"
992+
svn2git "$SVN_REPO" --empty-dirs --svn-branches --svn-ignore --rules <(echo "
993+
create repository git-repo
994+
end repository
995+
996+
match /trunk/
997+
repository git-repo
998+
branch master
999+
end match
1000+
1001+
match /branches/$
1002+
action recurse
1003+
end match
1004+
1005+
match /branches/([^/]+)/
1006+
repository git-repo
1007+
branch \1
1008+
end match
1009+
")
1010+
1011+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
1012+
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '/ignore-a'
1013+
}
1014+
1015+
@test 'branching with svn-ignore, svn-branches and empty-dirs parameter should not replace filled .gitignore files with empty ones' {
1016+
svn mkdir project-a
1017+
cd project-a
1018+
svn mkdir --parents trunk/dir-a
1019+
svn propset svn:ignore 'ignore-a' trunk/dir-a
1020+
svn commit -m 'add trunk/dir-a'
1021+
svn mkdir branches
1022+
svn cp trunk branches/branch-a
1023+
svn commit -m 'create branch-a'
1024+
1025+
cd "$TEST_TEMP_DIR"
1026+
svn2git "$SVN_REPO" --empty-dirs --svn-branches --svn-ignore --rules <(echo "
1027+
create repository git-repo
1028+
end repository
1029+
1030+
match /project-a/trunk/
1031+
repository git-repo
1032+
branch master
1033+
end match
1034+
1035+
match /project-a/branches/([^/]+)/
1036+
repository git-repo
1037+
branch \1
1038+
end match
1039+
1040+
match /project-a/(branches/)?$
1041+
action recurse
1042+
end match
1043+
")
1044+
1045+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
1046+
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '/ignore-a'
1047+
}

0 commit comments

Comments
 (0)