Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1842681

Browse files
Vampiretnyblom
authored andcommittedApr 18, 2020
If svn-ignore should have added a .gitignore file, do not overwrite it with an empty one
1 parent c384145 commit 1842681

File tree

2 files changed

+262
-0
lines changed

2 files changed

+262
-0
lines changed
 

‎src/svn.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
11341134

11351135
apr_hash_t *entries;
11361136
SVN_ERR(svn_fs_dir_entries(&entries, fs_root, parentKey.toStdString().c_str(), pool));
1137+
// directory is not empty
11371138
if (apr_hash_count(entries)!=0) {
11381139
return EXIT_FAILURE;
11391140
}
@@ -1144,6 +1145,19 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
11441145
index = cleanPath.lastIndexOf(slash);
11451146
QString parentPath = cleanPath.left(index);
11461147

1148+
// if svn-ignore should have added a .gitignore file, do not overwrite it with an empty one
1149+
// if svn:ignore could not be determined, stay safe and do not overwrite the .gitignore file
1150+
// even if then an empty directory might be missing
1151+
QString svnignore;
1152+
if (CommandLineParser::instance()->contains("svn-ignore")) {
1153+
if (fetchIgnoreProps(&svnignore, pool, parentKey.toStdString().c_str(), fs_root) != EXIT_SUCCESS) {
1154+
qWarning() << "Error fetching svn-properties (" << parentKey << ")";
1155+
return EXIT_FAILURE;
1156+
} else if (!svnignore.isNull()) {
1157+
return EXIT_FAILURE;
1158+
}
1159+
}
1160+
11471161
// Add gitignore-File
11481162
QString gitIgnorePath = parentPath + "/.gitignore";
11491163
QIODevice *io = txn->addFile(gitIgnorePath, 33188, 0);

‎test/empty-dirs.bats

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,251 @@ load 'common'
213213

214214
assert [ "$(grep -c '^M .* dir-a/file-a$' git-repo.fi)" -eq 1 ]
215215
}
216+
217+
@test 'deleting last file from a directory should add empty .gitignore with empty-dirs-parameter' {
218+
svn mkdir dir-a
219+
touch dir-a/file-a
220+
svn add dir-a/file-a
221+
svn commit -m 'add dir-a/file-a'
222+
svn rm dir-a/file-a
223+
svn commit -m 'delete dir-a/file-a'
224+
225+
cd "$TEST_TEMP_DIR"
226+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
227+
create repository git-repo
228+
end repository
229+
230+
match /
231+
repository git-repo
232+
branch master
233+
end match
234+
")
235+
236+
refute git -C git-repo show master:.gitignore
237+
assert git -C git-repo show master:dir-a/.gitignore
238+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
239+
}
240+
241+
@test 'deleting last file from a directory should add empty .gitignore with empty-dirs-parameter (nested)' {
242+
svn mkdir project-a
243+
cd project-a
244+
svn mkdir dir-a
245+
touch dir-a/file-a
246+
svn add dir-a/file-a
247+
svn commit -m 'add dir-a/file-a'
248+
svn rm dir-a/file-a
249+
svn commit -m 'delete dir-a/file-a'
250+
251+
cd "$TEST_TEMP_DIR"
252+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
253+
create repository git-repo
254+
end repository
255+
256+
match /project-a/
257+
repository git-repo
258+
branch master
259+
end match
260+
")
261+
262+
refute git -C git-repo show master:.gitignore
263+
assert git -C git-repo show master:dir-a/.gitignore
264+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
265+
}
266+
267+
@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' {
268+
svn mkdir dir-a
269+
touch dir-a/file-a
270+
svn add dir-a/file-a
271+
svn commit -m 'add dir-a/file-a'
272+
svn propset svn:ignore 'ignore-a' dir-a
273+
svn commit -m 'ignore ignore-a on dir-a'
274+
svn rm dir-a/file-a
275+
svn commit -m 'delete dir-a/file-a'
276+
277+
cd "$TEST_TEMP_DIR"
278+
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
279+
create repository git-repo
280+
end repository
281+
282+
match /
283+
repository git-repo
284+
branch master
285+
end match
286+
")
287+
288+
refute git -C git-repo show master:.gitignore
289+
assert git -C git-repo show master:dir-a/.gitignore
290+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
291+
}
292+
293+
@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)' {
294+
svn mkdir project-a
295+
cd project-a
296+
svn mkdir dir-a
297+
touch dir-a/file-a
298+
svn add dir-a/file-a
299+
svn commit -m 'add dir-a/file-a'
300+
svn propset svn:ignore 'ignore-a' dir-a
301+
svn commit -m 'ignore ignore-a on dir-a'
302+
svn rm dir-a/file-a
303+
svn commit -m 'delete dir-a/file-a'
304+
305+
cd "$TEST_TEMP_DIR"
306+
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
307+
create repository git-repo
308+
end repository
309+
310+
match /project-a/
311+
repository git-repo
312+
branch master
313+
end match
314+
")
315+
316+
refute git -C git-repo show master:.gitignore
317+
assert git -C git-repo show master:dir-a/.gitignore
318+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
319+
}
320+
321+
@test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter' {
322+
svn mkdir --parents dir-a/subdir-a
323+
svn commit -m 'add dir-a/subdir-a'
324+
svn rm dir-a/subdir-a
325+
svn commit -m 'delete dir-a/subdir-a'
326+
327+
cd "$TEST_TEMP_DIR"
328+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
329+
create repository git-repo
330+
end repository
331+
332+
match /
333+
repository git-repo
334+
branch master
335+
end match
336+
")
337+
338+
refute git -C git-repo show master:.gitignore
339+
assert git -C git-repo show master:dir-a/.gitignore
340+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
341+
}
342+
343+
@test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter (nested)' {
344+
svn mkdir project-a
345+
cd project-a
346+
svn mkdir --parents dir-a/subdir-a
347+
svn commit -m 'add dir-a/subdir-a'
348+
svn rm dir-a/subdir-a
349+
svn commit -m 'delete dir-a/subdir-a'
350+
351+
cd "$TEST_TEMP_DIR"
352+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
353+
create repository git-repo
354+
end repository
355+
356+
match /project-a/
357+
repository git-repo
358+
branch master
359+
end match
360+
")
361+
362+
refute git -C git-repo show master:.gitignore
363+
assert git -C git-repo show master:dir-a/.gitignore
364+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
365+
}
366+
367+
@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' {
368+
svn mkdir --parents dir-a/subdir-a
369+
svn commit -m 'add dir-a/subdir-a'
370+
svn propset svn:ignore 'ignore-a' dir-a
371+
svn commit -m 'ignore ignore-a on dir-a'
372+
svn rm dir-a/subdir-a
373+
svn commit -m 'delete dir-a/subdir-a'
374+
375+
cd "$TEST_TEMP_DIR"
376+
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
377+
create repository git-repo
378+
end repository
379+
380+
match /
381+
repository git-repo
382+
branch master
383+
end match
384+
")
385+
386+
refute git -C git-repo show master:.gitignore
387+
assert git -C git-repo show master:dir-a/.gitignore
388+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
389+
}
390+
391+
@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)' {
392+
svn mkdir project-a
393+
cd project-a
394+
svn mkdir --parents dir-a/subdir-a
395+
svn commit -m 'add dir-a/subdir-a'
396+
svn propset svn:ignore 'ignore-a' dir-a
397+
svn commit -m 'ignore ignore-a on dir-a'
398+
svn rm dir-a/subdir-a
399+
svn commit -m 'delete dir-a/subdir-a'
400+
401+
cd "$TEST_TEMP_DIR"
402+
svn2git "$SVN_REPO" --empty-dirs --svn-ignore --rules <(echo "
403+
create repository git-repo
404+
end repository
405+
406+
match /project-a/
407+
repository git-repo
408+
branch master
409+
end match
410+
")
411+
412+
refute git -C git-repo show master:.gitignore
413+
assert git -C git-repo show master:dir-a/.gitignore
414+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
415+
}
416+
417+
@test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter' {
418+
svn mkdir dir-a
419+
svn commit -m 'add dir-a'
420+
svn cp dir-a dir-b
421+
svn commit -m 'copy dir-a to dir-b'
422+
423+
cd "$TEST_TEMP_DIR"
424+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
425+
create repository git-repo
426+
end repository
427+
428+
match /
429+
repository git-repo
430+
branch master
431+
end match
432+
")
433+
434+
assert git -C git-repo show master:dir-a/.gitignore
435+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
436+
assert git -C git-repo show master:dir-b/.gitignore
437+
assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" ''
438+
}
439+
440+
@test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter (nested)' {
441+
svn mkdir project-a
442+
cd project-a
443+
svn mkdir dir-a
444+
svn commit -m 'add dir-a'
445+
svn cp dir-a dir-b
446+
svn commit -m 'copy dir-a to dir-b'
447+
448+
cd "$TEST_TEMP_DIR"
449+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
450+
create repository git-repo
451+
end repository
452+
453+
match /project-a/
454+
repository git-repo
455+
branch master
456+
end match
457+
")
458+
459+
assert git -C git-repo show master:dir-a/.gitignore
460+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" ''
461+
assert git -C git-repo show master:dir-b/.gitignore
462+
assert_equal "$(git -C git-repo show master:dir-b/.gitignore)" ''
463+
}

0 commit comments

Comments
 (0)
Please sign in to comment.