Skip to content

Commit 5d00890

Browse files
committed
Do not replace filled gitignore files with empty ones
1 parent f8bb129 commit 5d00890

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/svn.cpp

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

11011114
// Add gitignore-File

test/empty-dirs.bats

+66
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,69 @@ load 'common'
461461
assert git -C git-repo show master:dir-b/.gitignore
462462
assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" ''
463463
}
464+
465+
@test 'branching with svn-ignore, svn-branches and empty-dirs parameter should not replace filled .gitignore files with empty ones' {
466+
svn mkdir --parents trunk/dir-a
467+
svn propset svn:ignore 'ignore-a' trunk/dir-a
468+
svn commit -m 'add trunk/dir-a'
469+
svn mkdir branches
470+
svn cp trunk branches/branch-a
471+
svn commit -m 'create branch-a'
472+
473+
cd "$TEST_TEMP_DIR"
474+
svn2git "$SVN_REPO" --empty-dirs --svn-branches --svn-ignore --rules <(echo "
475+
create repository git-repo
476+
end repository
477+
478+
match /trunk/
479+
repository git-repo
480+
branch master
481+
end match
482+
483+
match /branches/$
484+
action recurse
485+
end match
486+
487+
match /branches/([^/]+)/
488+
repository git-repo
489+
branch \1
490+
end match
491+
")
492+
493+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
494+
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '/ignore-a'
495+
}
496+
497+
@test 'branching with svn-ignore, svn-branches and empty-dirs parameter should not replace filled .gitignore files with empty ones' {
498+
svn mkdir project-a
499+
cd project-a
500+
svn mkdir --parents trunk/dir-a
501+
svn propset svn:ignore 'ignore-a' trunk/dir-a
502+
svn commit -m 'add trunk/dir-a'
503+
svn mkdir branches
504+
svn cp trunk branches/branch-a
505+
svn commit -m 'create branch-a'
506+
507+
cd "$TEST_TEMP_DIR"
508+
svn2git "$SVN_REPO" --empty-dirs --svn-branches --svn-ignore --rules <(echo "
509+
create repository git-repo
510+
end repository
511+
512+
match /project-a/trunk/
513+
repository git-repo
514+
branch master
515+
end match
516+
517+
match /project-a/branches/([^/]+)/
518+
repository git-repo
519+
branch \1
520+
end match
521+
522+
match /project-a/(branches/)?$
523+
action recurse
524+
end match
525+
")
526+
527+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
528+
assert_equal "$(git -C git-repo show branch-a:dir-a/.gitignore)" '/ignore-a'
529+
}

0 commit comments

Comments
 (0)