diff --git a/src/svn.cpp b/src/svn.cpp index 29aa4bf..c85b922 100644 --- a/src/svn.cpp +++ b/src/svn.cpp @@ -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; } @@ -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); diff --git a/test/empty-dirs.bats b/test/empty-dirs.bats index b595876..674f1cf 100644 --- a/test/empty-dirs.bats +++ b/test/empty-dirs.bats @@ -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)" '' +}