@@ -386,6 +386,7 @@ class SvnRevision
386386 int fetchIgnoreProps (QString *ignore, apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
387387 int fetchUnknownProps (apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
388388private:
389+ int checkParentNoLongerEmpty (apr_pool_t *pool, const char *key, QString path, Repository::Transaction *txn);
389390 void splitPathName (const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
390391 QString *repository_p, QString *effectiveRepository_p, QString *branch_p, QString *path_p);
391392 int recursiveDumpDir (Repository::Transaction *txn, svn_fs_t *fs, svn_fs_root_t *fs_root,
@@ -868,6 +869,7 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
868869 if (ruledebug)
869870 qDebug () << " add/change file (" << key << " ->" << branch << path << " )" ;
870871 dumpBlob (txn, fs_root, key, path, pool);
872+ checkParentNoLongerEmpty (pool, key, path, txn);
871873 } else {
872874 if (ruledebug)
873875 qDebug () << " add/change dir (" << key << " ->" << branch << path << " )" ;
@@ -897,6 +899,7 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
897899 txn->deleteFile (path);
898900 checkParentNotEmpty (pool, key, path, fs_root, txn);
899901 }
902+ checkParentNoLongerEmpty (pool, key, path, txn);
900903
901904 // Add GitIgnore with svn:ignore
902905 int ignoreSet = false ;
@@ -1179,6 +1182,67 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
11791182 return EXIT_SUCCESS;
11801183}
11811184
1185+ int SvnRevision::checkParentNoLongerEmpty (apr_pool_t *pool, const char *key, QString path, Repository::Transaction *txn) {
1186+ if (!CommandLineParser::instance ()->contains (" empty-dirs" )) {
1187+ return EXIT_FAILURE;
1188+ }
1189+ QString slash = " /" ;
1190+ QString qkey = QString::fromUtf8 (key);
1191+ while (qkey.endsWith (' /' ))
1192+ qkey = qkey.mid (0 , qkey.length ()-1 );
1193+ int index = qkey.lastIndexOf (slash);
1194+ if (index == -1 ) {
1195+ return EXIT_FAILURE;
1196+ }
1197+ QString parentKey = qkey.left (index);
1198+
1199+ AprAutoPool subpool (pool);
1200+ svn_fs_root_t *previous_fs_root;
1201+ if (svn_fs_revision_root (&previous_fs_root, fs, revnum - 1 , subpool) != SVN_NO_ERROR) {
1202+ return EXIT_FAILURE;
1203+ }
1204+
1205+ apr_hash_t *entries;
1206+ // directory did not exist
1207+ if (svn_fs_dir_entries (&entries, previous_fs_root, parentKey.toStdString ().c_str (), pool) != SVN_NO_ERROR) {
1208+ return EXIT_FAILURE;
1209+ }
1210+
1211+ // directory was not empty
1212+ if (apr_hash_count (entries)!=0 ) {
1213+ return EXIT_FAILURE;
1214+ }
1215+
1216+ QString cleanPath = path;
1217+ while (cleanPath.endsWith (' /' ))
1218+ cleanPath = cleanPath.mid (0 , cleanPath.length ()-1 );
1219+ index = cleanPath.lastIndexOf (slash);
1220+ QString parentPath = cleanPath.left (index);
1221+
1222+ // we are in the root directory, we did not add a .gitignore here
1223+ if (index == -1 ) {
1224+ return EXIT_FAILURE;
1225+ }
1226+
1227+ // if svn-ignore should have added a .gitignore file, do not consider the directory empty
1228+ // if svn:ignore could not be determined, stay safe and do not consider the directory empty
1229+ // even if then an empty .gitignore might be left over
1230+ QString svnignore;
1231+ if (CommandLineParser::instance ()->contains (" svn-ignore" )) {
1232+ if (fetchIgnoreProps (&svnignore, pool, parentKey.toStdString ().c_str (), previous_fs_root) != EXIT_SUCCESS) {
1233+ qWarning () << " Error fetching svn-properties (" << parentKey << " )" ;
1234+ return EXIT_FAILURE;
1235+ } else if (!svnignore.isNull ()) {
1236+ return EXIT_FAILURE;
1237+ }
1238+ }
1239+
1240+ // Delete gitignore-File
1241+ QString gitIgnorePath = parentPath + " /.gitignore" ;
1242+ txn->deleteFile (gitIgnorePath);
1243+ return EXIT_SUCCESS;
1244+ }
1245+
11821246int SvnRevision::addGitIgnoreOnBranch (apr_pool_t *pool, QString key, QString path,
11831247 svn_fs_root_t *fs_root, Repository::Transaction *txn)
11841248{
0 commit comments