@@ -408,6 +408,8 @@ class SvnRevision
408408 int recurse (const char *path, const svn_fs_path_change2_t *change,
409409 const char *path_from, const MatchRuleList &matchRules, svn_revnum_t rev_from,
410410 apr_hash_t *changes, apr_pool_t *pool);
411+ int addGitIgnore (apr_pool_t *pool, const char *key, QString path,
412+ svn_fs_root_t *fs_root, Repository::Transaction *txn);
411413private:
412414 void splitPathName (const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
413415 QString *repository_p, QString *effectiveRepository_p, QString *branch_p, QString *path_p);
@@ -594,7 +596,18 @@ int SvnRevision::exportEntry(const char *key, const svn_fs_path_change2_t *chang
594596 // is this a directory?
595597 svn_boolean_t is_dir;
596598 SVN_ERR (svn_fs_is_dir (&is_dir, fs_root, key, revpool));
597- if (is_dir) {
599+ // Adding newly created directories
600+ if (is_dir && change->change_kind == svn_fs_path_change_add && path_from == NULL && CommandLineParser::instance ()->contains (" empty-dirs" )) {
601+ QString keyQString = key;
602+ // Skipping SVN-directory-layout
603+ if (keyQString.endsWith (" /trunk" ) || keyQString.endsWith (" /branches" ) || keyQString.endsWith (" /tags" )) {
604+ // qDebug() << "Skipping SVN-directory-layout:" << keyQString;
605+ return EXIT_SUCCESS;
606+ }
607+ needCommit = true ;
608+ // qDebug() << "Adding directory:" << key;
609+ }
610+ else if (is_dir) {
598611 if (change->change_kind == svn_fs_path_change_modify ||
599612 change->change_kind == svn_fs_path_change_add) {
600613 if (path_from == NULL ) {
@@ -845,6 +858,12 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change2_t *ch
845858 } else {
846859 if (ruledebug)
847860 qDebug () << " add/change dir (" << key << " ->" << branch << path << " )" ;
861+ // Add GitIgnore for empty directories
862+ if (CommandLineParser::instance ()->contains (" empty-dirs" )) {
863+ if (addGitIgnore (pool, key, path, fs_root, txn) == EXIT_SUCCESS) {
864+ return EXIT_SUCCESS;
865+ }
866+ }
848867 txn->deleteFile (path);
849868 recursiveDumpDir (txn, fs_root, key, path, pool);
850869 }
@@ -928,3 +947,23 @@ int SvnRevision::recurse(const char *path, const svn_fs_path_change2_t *change,
928947
929948 return EXIT_SUCCESS;
930949}
950+
951+ int SvnRevision::addGitIgnore (apr_pool_t *pool, const char *key, QString path,
952+ svn_fs_root_t *fs_root, Repository::Transaction *txn)
953+ {
954+ // Check for number of subfiles
955+ apr_hash_t *entries;
956+ SVN_ERR (svn_fs_dir_entries (&entries, fs_root, key, pool));
957+ // Return if any subfiles
958+ if (apr_hash_count (entries)!=0 ) {
959+ return EXIT_FAILURE;
960+ }
961+
962+ // Add empty gitignore-File
963+ QString gitIgnorePath = path + " .gitignore" ;
964+ qDebug () << " Adding GitIgnore-File" << gitIgnorePath;
965+ QIODevice *io = txn->addFile (gitIgnorePath, 33188 , 0 );
966+ io->putChar (' \n ' );
967+
968+ return EXIT_SUCCESS;
969+ }
0 commit comments