@@ -386,6 +386,7 @@ class SvnRevision
386
386
int fetchIgnoreProps (QString *ignore, apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
387
387
int fetchUnknownProps (apr_pool_t *pool, const char *key, svn_fs_root_t *fs_root);
388
388
private:
389
+ int checkParentNoLongerEmpty (apr_pool_t *pool, const char *key, QString path, Repository::Transaction *txn);
389
390
void splitPathName (const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
390
391
QString *repository_p, QString *effectiveRepository_p, QString *branch_p, QString *path_p);
391
392
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
868
869
if (ruledebug)
869
870
qDebug () << " add/change file (" << key << " ->" << branch << path << " )" ;
870
871
dumpBlob (txn, fs_root, key, path, pool);
872
+ checkParentNoLongerEmpty (pool, key, path, txn);
871
873
} else {
872
874
if (ruledebug)
873
875
qDebug () << " add/change dir (" << key << " ->" << branch << path << " )" ;
@@ -897,6 +899,7 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
897
899
txn->deleteFile (path);
898
900
checkParentNotEmpty (pool, key, path, fs_root, txn);
899
901
}
902
+ checkParentNoLongerEmpty (pool, key, path, txn);
900
903
901
904
// Add GitIgnore with svn:ignore
902
905
int ignoreSet = false ;
@@ -1151,6 +1154,67 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
1151
1154
return EXIT_SUCCESS;
1152
1155
}
1153
1156
1157
+ int SvnRevision::checkParentNoLongerEmpty (apr_pool_t *pool, const char *key, QString path, Repository::Transaction *txn) {
1158
+ if (!CommandLineParser::instance ()->contains (" empty-dirs" )) {
1159
+ return EXIT_FAILURE;
1160
+ }
1161
+ QString slash = " /" ;
1162
+ QString qkey = QString::fromUtf8 (key);
1163
+ while (qkey.endsWith (' /' ))
1164
+ qkey = qkey.mid (0 , qkey.length ()-1 );
1165
+ int index = qkey.lastIndexOf (slash);
1166
+ if (index == -1 ) {
1167
+ return EXIT_FAILURE;
1168
+ }
1169
+ QString parentKey = qkey.left (index );
1170
+
1171
+ AprAutoPool subpool (pool);
1172
+ svn_fs_root_t *previous_fs_root;
1173
+ if (svn_fs_revision_root (&previous_fs_root, fs, revnum - 1 , subpool) != SVN_NO_ERROR) {
1174
+ return EXIT_FAILURE;
1175
+ }
1176
+
1177
+ apr_hash_t *entries;
1178
+ // directory did not exist
1179
+ if (svn_fs_dir_entries (&entries, previous_fs_root, parentKey.toStdString ().c_str (), pool) != SVN_NO_ERROR) {
1180
+ return EXIT_FAILURE;
1181
+ }
1182
+
1183
+ // directory was not empty
1184
+ if (apr_hash_count (entries)!=0 ) {
1185
+ return EXIT_FAILURE;
1186
+ }
1187
+
1188
+ QString cleanPath = path;
1189
+ while (cleanPath.endsWith (' /' ))
1190
+ cleanPath = cleanPath.mid (0 , cleanPath.length ()-1 );
1191
+ index = cleanPath.lastIndexOf (slash);
1192
+ QString parentPath = cleanPath.left (index );
1193
+
1194
+ // we are in the root directory, we did not add a .gitignore here
1195
+ if (index == -1 ) {
1196
+ return EXIT_FAILURE;
1197
+ }
1198
+
1199
+ // if svn-ignore should have added a .gitignore file, do not consider the directory empty
1200
+ // if svn:ignore could not be determined, stay safe and do not consider the directory empty
1201
+ // even if then an empty .gitignore might be left over
1202
+ QString svnignore;
1203
+ if (CommandLineParser::instance ()->contains (" svn-ignore" )) {
1204
+ if (fetchIgnoreProps (&svnignore, pool, parentKey.toStdString ().c_str (), previous_fs_root) != EXIT_SUCCESS) {
1205
+ qWarning () << " Error fetching svn-properties (" << parentKey << " )" ;
1206
+ return EXIT_FAILURE;
1207
+ } else if (!svnignore.isNull ()) {
1208
+ return EXIT_FAILURE;
1209
+ }
1210
+ }
1211
+
1212
+ // Delete gitignore-File
1213
+ QString gitIgnorePath = parentPath + " /.gitignore" ;
1214
+ txn->deleteFile (gitIgnorePath);
1215
+ return EXIT_SUCCESS;
1216
+ }
1217
+
1154
1218
int SvnRevision::addGitIgnoreOnBranch (apr_pool_t *pool, QString key, QString path,
1155
1219
svn_fs_root_t *fs_root, Repository::Transaction *txn)
1156
1220
{
0 commit comments