Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60bfc16

Browse files
Vampiretnyblom
authored andcommitted
Fix .gitignore handling in root directory
1 parent f8bb129 commit 60bfc16

File tree

3 files changed

+154
-1
lines changed

3 files changed

+154
-1
lines changed

‎src/svn.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,14 +1099,20 @@ int SvnRevision::addGitIgnore(apr_pool_t *pool, const char *key, QString path,
10991099
}
11001100

11011101
// Add gitignore-File
1102-
QString gitIgnorePath = path + ".gitignore";
1102+
QString gitIgnorePath = path == "/" ? ".gitignore" : path + ".gitignore";
11031103
if (content) {
11041104
QIODevice *io = txn->addFile(gitIgnorePath, 33188, strlen(content));
11051105
if (!CommandLineParser::instance()->contains("dry-run")) {
11061106
io->write(content);
11071107
io->putChar('\n');
11081108
}
11091109
} else {
1110+
// no empty placeholder .gitignore for repository root
1111+
// this should be handled previously already, just a
1112+
// security measure here.
1113+
if (path == "/") {
1114+
return EXIT_FAILURE;
1115+
}
11101116
QIODevice *io = txn->addFile(gitIgnorePath, 33188, 0);
11111117
if (!CommandLineParser::instance()->contains("dry-run")) {
11121118
io->putChar('\n');
@@ -1145,6 +1151,11 @@ int SvnRevision::checkParentNotEmpty(apr_pool_t *pool, const char *key, QString
11451151
index = cleanPath.lastIndexOf(slash);
11461152
QString parentPath = cleanPath.left(index);
11471153

1154+
// we are in the root directory, do not add a .gitignore here
1155+
if (index == -1) {
1156+
return EXIT_FAILURE;
1157+
}
1158+
11481159
// if svn-ignore should have added a .gitignore file, do not overwrite it with an empty one
11491160
// if svn:ignore could not be determined, stay safe and do not overwrite the .gitignore file
11501161
// even if then an empty directory might be missing

‎test/empty-dirs.bats

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,52 @@ load 'common'
318318
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
319319
}
320320

321+
@test 'deleting last file from root should not add empty .gitignore with empty-dirs-parameter' {
322+
touch file-a
323+
svn add file-a
324+
svn commit -m 'add file-a'
325+
svn rm file-a
326+
svn commit -m 'delete file-a'
327+
328+
cd "$TEST_TEMP_DIR"
329+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
330+
create repository git-repo
331+
end repository
332+
333+
match /
334+
repository git-repo
335+
branch master
336+
end match
337+
")
338+
339+
refute git -C git-repo show master:.gitignore
340+
refute git -C git-repo show master:file-a/.gitignore
341+
}
342+
343+
@test 'deleting last file from root should not add empty .gitignore with empty-dirs-parameter (nested)' {
344+
svn mkdir project-a
345+
cd project-a
346+
touch file-a
347+
svn add file-a
348+
svn commit -m 'add file-a'
349+
svn rm file-a
350+
svn commit -m 'delete file-a'
351+
352+
cd "$TEST_TEMP_DIR"
353+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
354+
create repository git-repo
355+
end repository
356+
357+
match /project-a/
358+
repository git-repo
359+
branch master
360+
end match
361+
")
362+
363+
refute git -C git-repo show master:.gitignore
364+
refute git -C git-repo show master:file-a/.gitignore
365+
}
366+
321367
@test 'deleting last directory from a directory should add empty .gitignore with empty-dirs-parameter' {
322368
svn mkdir --parents dir-a/subdir-a
323369
svn commit -m 'add dir-a/subdir-a'
@@ -414,6 +460,50 @@ load 'common'
414460
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" '/ignore-a'
415461
}
416462

463+
@test 'deleting last directory from root should not add empty .gitignore with empty-dirs-parameter' {
464+
svn mkdir dir-a
465+
svn commit -m 'add dir-a'
466+
svn rm dir-a
467+
svn commit -m 'delete dir-a'
468+
469+
cd "$TEST_TEMP_DIR"
470+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
471+
create repository git-repo
472+
end repository
473+
474+
match /
475+
repository git-repo
476+
branch master
477+
end match
478+
")
479+
480+
refute git -C git-repo show master:.gitignore
481+
refute git -C git-repo show master:dir-a/.gitignore
482+
}
483+
484+
@test 'deleting last directory from root should not add empty .gitignore with empty-dirs-parameter (nested)' {
485+
svn mkdir project-a
486+
cd project-a
487+
svn mkdir dir-a
488+
svn commit -m 'add dir-a'
489+
svn rm dir-a
490+
svn commit -m 'delete dir-a'
491+
492+
cd "$TEST_TEMP_DIR"
493+
svn2git "$SVN_REPO" --empty-dirs --rules <(echo "
494+
create repository git-repo
495+
end repository
496+
497+
match /project-a/
498+
repository git-repo
499+
branch master
500+
end match
501+
")
502+
503+
refute git -C git-repo show master:.gitignore
504+
refute git -C git-repo show master:dir-a/.gitignore
505+
}
506+
417507
@test 'copying an empty directory should put empty .gitignore file to copy with empty-dirs parameter' {
418508
svn mkdir dir-a
419509
svn commit -m 'add dir-a'

‎test/svn-ignore.bats

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,58 @@ load 'common'
360360
assert git -C git-repo show master:dir-a/file-a
361361
}
362362

363+
@test 'svn-ignore translation should be done properly on the root directory' {
364+
svn propset svn:ignore $'ignore-a\nignore-b' .
365+
svn commit -m 'ignore ignore-a and ignore-b on root'
366+
svn propset svn:global-ignores 'ignore-c' .
367+
svn commit -m 'ignore ignore-c on root and descendents'
368+
369+
cd "$TEST_TEMP_DIR"
370+
svn2git "$SVN_REPO" --svn-ignore --rules <(echo "
371+
create repository git-repo
372+
end repository
373+
374+
match /
375+
repository git-repo
376+
branch master
377+
end match
378+
")
379+
380+
assert_equal "$(git -C git-repo show master:.gitignore)" "$(cat <<-EOF
381+
/ignore-a
382+
/ignore-b
383+
ignore-c
384+
EOF
385+
)"
386+
}
387+
388+
@test 'svn-ignore translation should be done properly on the root directory (nested)' {
389+
svn mkdir project-a
390+
cd project-a
391+
svn propset svn:ignore $'ignore-a\nignore-b' .
392+
svn commit -m 'ignore ignore-a and ignore-b on root'
393+
svn propset svn:global-ignores 'ignore-c' .
394+
svn commit -m 'ignore ignore-c on root and descendents'
395+
396+
cd "$TEST_TEMP_DIR"
397+
svn2git "$SVN_REPO" --svn-ignore --rules <(echo "
398+
create repository git-repo
399+
end repository
400+
401+
match /project-a/
402+
repository git-repo
403+
branch master
404+
end match
405+
")
406+
407+
assert_equal "$(git -C git-repo show master:.gitignore)" "$(cat <<-EOF
408+
/ignore-a
409+
/ignore-b
410+
ignore-c
411+
EOF
412+
)"
413+
}
414+
363415
@test 'gitignore file should be removed if all svn-ignores are removed' {
364416
svn mkdir dir-a
365417
svn propset svn:ignore 'ignore-a' dir-a

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /