git-svn: fix committing to subdirectories, add tests
I broke this part with the URL minimization; since git-svn will now try to connect to the root of the repository and will end up writing files there if it can... Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 26, 2007 at 01:32 UTC
d3a840dc74d2098c31aac1b89093d847e1d33dd8
3 files changed
+48
-4
git-svn.perl
+10
-4
@@ -354,7 +354,7 @@ sub cmd_dcommit {
354
my $pool = SVN::Pool->new;
355
my %ed_opts = ( r => $last_rev,
356
ra => $ra->dup,
357
- svn_path => $ra->{svn_path} );
357
+ svn_path => $gs->{path} );
358
my $ed = SVN::Git::Editor->new(\%ed_opts,
359
$ra->get_commit_editor($log,
360
sub { print "Committed r$_[0]\n";
@@ -437,6 +437,7 @@ sub cmd_commit_diff {
437
my $usage = "Usage: $0 commit-diff -r<revision> ".
438
"<tree-ish> <tree-ish> [<URL>]\n";
439
fatal($usage) if (!defined $ta || !defined $tb);
440
+ my $svn_path;
441
if (!defined $url) {
442
my $gs = eval { Git::SVN->new };
443
if (!$gs) {
@@ -444,6 +445,7 @@ sub cmd_commit_diff {
445
"the command-line\n", $usage);
446
}
447
$url = $gs->{url};
448
+ $svn_path = $gs->{path};
449
}
450
unless (defined $_revision) {
451
fatal("-r|--revision is a required argument\n", $usage);
@@ -459,6 +461,7 @@ sub cmd_commit_diff {
461
$_message ||= get_commit_entry($tb)->{log};
462
}
463
my $ra ||= Git::SVN::Ra->new($url);
464
+ $svn_path ||= $ra->{svn_path};
465
my $r = $_revision;
466
if ($r eq 'HEAD') {
467
$r = $ra->get_latest_revnum;
@@ -468,7 +471,7 @@ sub cmd_commit_diff {
471
my $pool = SVN::Pool->new;
472
my %ed_opts = ( r => $r,
473
ra => $ra->dup,
471
- svn_path => $ra->{svn_path} );
474
+ svn_path => $svn_path );
475
my $ed = SVN::Git::Editor->new(\%ed_opts,
476
$ra->get_commit_editor($_message,
477
sub { print "Committed r$_[0]\n" }),
@@ -1374,7 +1377,7 @@ sub set_tree {
1377
my $pool = SVN::Pool->new;
1378
my $ed = SVN::Git::Editor->new({ r => $self->{last_rev},
1379
ra => $self->ra->dup,
1377
- svn_path => $self->ra->{svn_path}
1380
+ svn_path => $self->{path}
1381
},
1382
$self->ra->get_commit_editor(
1383
$log_entry->{log}, sub {
@@ -1902,6 +1905,8 @@ sub new {
1905
$self->{pool} = SVN::Pool->new;
1906
$self->{bat} = { '' => $self->open_root($self->{r}, $self->{pool}) };
1907
$self->{rm} = { };
1908
+ $self->{path_prefix} = length $self->{svn_path} ?
1909
+ "$self->{svn_path}/" : '';
1910
require Digest::MD5;
1911
return $self;
1912
}
@@ -1911,7 +1916,8 @@ sub split_path {
1916
}
1917
1918
sub repo_path {
1914
- (defined $_[1] && length $_[1]) ? $_[1] : ''
1919
+ my ($self, $path) = @_;
1920
+ $self->{path_prefix}.(defined $path ? $path : '');
1921
}
1922
1923
sub url_path {
t/t9100-git-svn-basic.sh
+29
@@ -236,4 +236,33 @@ test_expect_success \
236
'^:refs/remotes/git-svn$'
237
"
238
239
+test_expect_success 'able to dcommit to a subdirectory' "
240
+ git-svn fetch -i bar &&
241
+ git checkout -b my-bar refs/remotes/bar &&
242
+ echo abc > d &&
243
+ git update-index --add d &&
244
+ git commit -m '/bar/d should be in the log' &&
245
+ git-svn dcommit -i bar &&
246
+ test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
247
+ mkdir newdir &&
248
+ echo new > newdir/dir &&
249
+ git update-index --add newdir/dir &&
250
+ git commit -m 'add a new directory' &&
251
+ git-svn dcommit -i bar &&
252
+ test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
253
+ echo foo >> newdir/dir &&
254
+ git update-index newdir/dir &&
255
+ git commit -m 'modify a file in new directory' &&
256
+ git-svn dcommit -i bar &&
257
+ test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
258
+ "
259
+
260
+test_expect_success 'able to set-tree to a subdirectory' "
261
+ echo cba > d &&
262
+ git update-index d &&
263
+ git commit -m 'update /bar/d' &&
264
+ git-svn set-tree -i bar HEAD &&
265
+ test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
266
+ "
267
+
268
test_done
t/t9105-git-svn-commit-diff.sh
+9
@@ -31,4 +31,13 @@ test_expect_success 'test the commit-diff command' "
31
cmp readme wc/readme
32
"
33
34
+test_expect_success 'commit-diff to a sub-directory (with git-svn config)' "
35
+ svn import -m 'sub-directory' import $svnrepo/subdir &&
36
+ git-svn init $svnrepo/subdir &&
37
+ git-svn fetch &&
38
+ git-svn commit-diff -r3 '$prev' '$head' &&
39
+ svn cat $svnrepo/subdir/readme > readme.2 &&
40
+ cmp readme readme.2
41
+ "
42
+
43
test_done