Skip to content

Commit 698a9ab

Browse files
committed
Merge branch 'mh/git-svn-automkdirs'
* mh/git-svn-automkdirs: git-svn: add an option to skip the creation of empty directories
2 parents 95fd6e2 + 55f9d7a commit 698a9ab

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Documentation/git-svn.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ Any other arguments are passed directly to 'git log'
350350
Empty directories are automatically recreated when using
351351
"git svn clone" and "git svn rebase", so "mkdirs" is intended
352352
for use after commands like "git checkout" or "git reset".
353+
(See the svn-remote.<name>.automkdirs config file option for
354+
more information.)
353355

354356
'commit-diff'::
355357
Commits the diff of two tree-ish arguments from the
@@ -680,6 +682,14 @@ svn.pathnameencoding::
680682
locales to avoid corrupted file names with non-ASCII characters.
681683
Valid encodings are the ones supported by Perl's Encode module.
682684

685+
svn-remote.<name>.automkdirs::
686+
Normally, the "git svn clone" and "git svn rebase" commands
687+
attempt to recreate empty directories that are in the
688+
Subversion repository. If this option is set to "false", then
689+
empty directories will only be created if the "git svn mkdirs"
690+
command is run explicitly. If unset, 'git svn' assumes this
691+
option to be "true".
692+
683693
Since the noMetadata, rewriteRoot, rewriteUUID, useSvnsyncProps and useSvmProps
684694
options all affect the metadata generated and used by 'git svn'; they
685695
*must* be set in the configuration file before any history is imported

git-svn.perl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,15 @@ sub cmd_find_rev {
784784
print "$result\n" if $result;
785785
}
786786

787+
sub auto_create_empty_directories {
788+
my ($gs) = @_;
789+
my $var = eval { command_oneline('config', '--get', '--bool',
790+
"svn-remote.$gs->{repo_id}.automkdirs") };
791+
# By default, create empty directories by consulting the unhandled log,
792+
# but allow setting it to 'false' to skip it.
793+
return !($var && $var eq 'false');
794+
}
795+
787796
sub cmd_rebase {
788797
command_noisy(qw/update-index --refresh/);
789798
my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
@@ -807,7 +816,9 @@ sub cmd_rebase {
807816
$_fetch_all ? $gs->fetch_all : $gs->fetch;
808817
}
809818
command_noisy(rebase_cmd(), $gs->refname);
810-
$gs->mkemptydirs;
819+
if (auto_create_empty_directories($gs)) {
820+
$gs->mkemptydirs;
821+
}
811822
}
812823

813824
sub cmd_show_ignore {
@@ -1245,7 +1256,9 @@ sub post_fetch_checkout {
12451256
command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
12461257
print STDERR "Checked out HEAD:\n ",
12471258
$gs->full_url, " r", $gs->last_rev, "\n";
1248-
$gs->mkemptydirs($gs->last_rev);
1259+
if (auto_create_empty_directories($gs)) {
1260+
$gs->mkemptydirs($gs->last_rev);
1261+
}
12491262
}
12501263

12511264
sub complete_svn_url {

t/t9146-git-svn-empty-dirs.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ test_expect_success 'empty directories exist' '
2828
)
2929
'
3030

31+
test_expect_success 'option automkdirs set to false' '
32+
(
33+
git svn init "$svnrepo" cloned-no-mkdirs &&
34+
cd cloned-no-mkdirs &&
35+
git config svn-remote.svn.automkdirs false &&
36+
git svn fetch &&
37+
for i in a b c d d/e d/e/f "weird file name"
38+
do
39+
if test -d "$i"
40+
then
41+
echo >&2 "$i exists"
42+
exit 1
43+
fi
44+
done
45+
)
46+
'
47+
3148
test_expect_success 'more emptiness' '
3249
svn_cmd mkdir -m "bang bang" "$svnrepo"/"! !"
3350
'

0 commit comments

Comments
 (0)