Skip to content

If svn-ignore should have added a .gitignore file, do not overwrite it with an empty one #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/svn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString

apr_hash_t *entries;
SVN_ERR(svn_fs_dir_entries(&entries, fs_root, parentKey.toStdString().c_str(), pool));
// directory is not empty
if (apr_hash_count(entries)!=0) {
return EXIT_FAILURE;
}
Expand All @@ -1141,6 +1142,19 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
index = cleanPath.lastIndexOf(slash);
QString parentPath = cleanPath.left(index);

// if svn-ignore should have added a .gitignore file, do not overwrite it with an empty one
// if svn:ignore could not be determined, stay safe and do not overwrite the .gitignore file
// even if then an empty directory might be missing
QString svnignore;
if (CommandLineParser::instance()->contains("svn-ignore")) {
if (fetchIgnoreProps(&svnignore, pool, parentKey.toStdString().c_str(), fs_root) != EXIT_SUCCESS) {
qWarning() << "Error fetching svn-properties (" << parentKey << ")";
return EXIT_FAILURE;
} else if (!svnignore.isNull()) {
return EXIT_FAILURE;
}
}

// Add gitignore-File
QString gitIgnorePath = parentPath + "/.gitignore";
QIODevice *io = txn->addFile(gitIgnorePath, 33188, 0);
Expand Down
248 changes: 248 additions & 0 deletions test/empty-dirs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,251 @@ load 'common'

assert [ "$(grep -c '^M .* dir-a/file-a$' git-repo.fi)" -eq 1 ]
}

@test 'deleting last file from a directory should add empty .gitignore with empty-dirs-parameter' {
svn mkdir dir-a
touch dir-a/file-a
svn add dir-a/file-a
svn commit -m 'add dir-a/file-a'
svn rm dir-a/file-a
svn commit -m 'delete dir-a/file-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
create repository git-repo
end repository

match /
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
}

@test 'deleting last file from a directory should add empty .gitignore with empty-dirs-parameter (nested)' {
svn mkdir project-a
cd project-a
svn mkdir dir-a
touch dir-a/file-a
svn add dir-a/file-a
svn commit -m 'add dir-a/file-a'
svn rm dir-a/file-a
svn commit -m 'delete dir-a/file-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
create repository git-repo
end repository

match /project-a/
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
}

@test 'deleting last file from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property' {
svn mkdir dir-a
touch dir-a/file-a
svn add dir-a/file-a
svn commit -m 'add dir-a/file-a'
svn propset svn:ignore 'ignore-a' dir-a
svn commit -m 'ignore ignore-a on dir-a'
svn rm dir-a/file-a
svn commit -m 'delete dir-a/file-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
create repository git-repo
end repository

match /
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
}

@test 'deleting last file from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property (nested)' {
svn mkdir project-a
cd project-a
svn mkdir dir-a
touch dir-a/file-a
svn add dir-a/file-a
svn commit -m 'add dir-a/file-a'
svn propset svn:ignore 'ignore-a' dir-a
svn commit -m 'ignore ignore-a on dir-a'
svn rm dir-a/file-a
svn commit -m 'delete dir-a/file-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
create repository git-repo
end repository

match /project-a/
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
}

@test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter' {
svn mkdir --parents dir-a/subdir-a
svn commit -m 'add dir-a/subdir-a'
svn rm dir-a/subdir-a
svn commit -m 'delete dir-a/subdir-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
create repository git-repo
end repository

match /
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
}

@test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter (nested)' {
svn mkdir project-a
cd project-a
svn mkdir --parents dir-a/subdir-a
svn commit -m 'add dir-a/subdir-a'
svn rm dir-a/subdir-a
svn commit -m 'delete dir-a/subdir-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
create repository git-repo
end repository

match /project-a/
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
}

@test 'deleting last directory from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property' {
svn mkdir --parents dir-a/subdir-a
svn commit -m 'add dir-a/subdir-a'
svn propset svn:ignore 'ignore-a' dir-a
svn commit -m 'ignore ignore-a on dir-a'
svn rm dir-a/subdir-a
svn commit -m 'delete dir-a/subdir-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
create repository git-repo
end repository

match /
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
}

@test 'deleting last directory from a directory should not add empty .gitignore with empty-dirs-parameter and svn-ignore-parameter if there is an svn:ignore property (nested)' {
svn mkdir project-a
cd project-a
svn mkdir --parents dir-a/subdir-a
svn commit -m 'add dir-a/subdir-a'
svn propset svn:ignore 'ignore-a' dir-a
svn commit -m 'ignore ignore-a on dir-a'
svn rm dir-a/subdir-a
svn commit -m 'delete dir-a/subdir-a'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
create repository git-repo
end repository

match /project-a/
repository git-repo
branch master
end match
")

refute git -C git-repo show master:.gitignore
assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
}

@test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter' {
svn mkdir dir-a
svn commit -m 'add dir-a'
svn cp dir-a dir-b
svn commit -m 'copy dir-a to dir-b'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
create repository git-repo
end repository

match /
repository git-repo
branch master
end match
")

assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
assert git -C git-repo show master:dir-b/.gitignore
assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" ''
}

@test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter (nested)' {
svn mkdir project-a
cd project-a
svn mkdir dir-a
svn commit -m 'add dir-a'
svn cp dir-a dir-b
svn commit -m 'copy dir-a to dir-b'

cd "$TEST_TEMP_DIR"
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
create repository git-repo
end repository

match /project-a/
repository git-repo
branch master
end match
")

assert git -C git-repo show master:dir-a/.gitignore
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
assert git -C git-repo show master:dir-b/.gitignore
assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" ''
}