Skip to content

Commit

Permalink
git-svn: fix committing to subdirectories, add tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Wong committed Feb 23, 2007
1 parent 3ebe8df commit d3a840d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
14 changes: 10 additions & 4 deletions git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ sub cmd_dcommit {
my $pool = SVN::Pool->new;
my %ed_opts = ( r => $last_rev,
ra => $ra->dup,
svn_path => $ra->{svn_path} );
svn_path => $gs->{path} );
my $ed = SVN::Git::Editor->new(\%ed_opts,
$ra->get_commit_editor($log,
sub { print "Committed r$_[0]\n";
Expand Down Expand Up @@ -437,13 +437,15 @@ sub cmd_commit_diff {
my $usage = "Usage: $0 commit-diff -r<revision> ".
"<tree-ish> <tree-ish> [<URL>]\n";
fatal($usage) if (!defined $ta || !defined $tb);
my $svn_path;
if (!defined $url) {
my $gs = eval { Git::SVN->new };
if (!$gs) {
fatal("Needed URL or usable git-svn --id in ",
"the command-line\n", $usage);
}
$url = $gs->{url};
$svn_path = $gs->{path};
}
unless (defined $_revision) {
fatal("-r|--revision is a required argument\n", $usage);
Expand All @@ -459,6 +461,7 @@ sub cmd_commit_diff {
$_message ||= get_commit_entry($tb)->{log};
}
my $ra ||= Git::SVN::Ra->new($url);
$svn_path ||= $ra->{svn_path};
my $r = $_revision;
if ($r eq 'HEAD') {
$r = $ra->get_latest_revnum;
Expand All @@ -468,7 +471,7 @@ sub cmd_commit_diff {
my $pool = SVN::Pool->new;
my %ed_opts = ( r => $r,
ra => $ra->dup,
svn_path => $ra->{svn_path} );
svn_path => $svn_path );
my $ed = SVN::Git::Editor->new(\%ed_opts,
$ra->get_commit_editor($_message,
sub { print "Committed r$_[0]\n" }),
Expand Down Expand Up @@ -1374,7 +1377,7 @@ sub set_tree {
my $pool = SVN::Pool->new;
my $ed = SVN::Git::Editor->new({ r => $self->{last_rev},
ra => $self->ra->dup,
svn_path => $self->ra->{svn_path}
svn_path => $self->{path}
},
$self->ra->get_commit_editor(
$log_entry->{log}, sub {
Expand Down Expand Up @@ -1902,6 +1905,8 @@ sub new {
$self->{pool} = SVN::Pool->new;
$self->{bat} = { '' => $self->open_root($self->{r}, $self->{pool}) };
$self->{rm} = { };
$self->{path_prefix} = length $self->{svn_path} ?
"$self->{svn_path}/" : '';
require Digest::MD5;
return $self;
}
Expand All @@ -1911,7 +1916,8 @@ sub split_path {
}

sub repo_path {
(defined $_[1] && length $_[1]) ? $_[1] : ''
my ($self, $path) = @_;
$self->{path_prefix}.(defined $path ? $path : '');
}

sub url_path {
Expand Down
29 changes: 29 additions & 0 deletions t/t9100-git-svn-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,33 @@ test_expect_success \
'^:refs/remotes/git-svn$'
"

test_expect_success 'able to dcommit to a subdirectory' "
git-svn fetch -i bar &&
git checkout -b my-bar refs/remotes/bar &&
echo abc > d &&
git update-index --add d &&
git commit -m '/bar/d should be in the log' &&
git-svn dcommit -i bar &&
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
mkdir newdir &&
echo new > newdir/dir &&
git update-index --add newdir/dir &&
git commit -m 'add a new directory' &&
git-svn dcommit -i bar &&
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
echo foo >> newdir/dir &&
git update-index newdir/dir &&
git commit -m 'modify a file in new directory' &&
git-svn dcommit -i bar &&
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
"

test_expect_success 'able to set-tree to a subdirectory' "
echo cba > d &&
git update-index d &&
git commit -m 'update /bar/d' &&
git-svn set-tree -i bar HEAD &&
test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
"

test_done
9 changes: 9 additions & 0 deletions t/t9105-git-svn-commit-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ test_expect_success 'test the commit-diff command' "
cmp readme wc/readme
"

test_expect_success 'commit-diff to a sub-directory (with git-svn config)' "
svn import -m 'sub-directory' import $svnrepo/subdir &&
git-svn init $svnrepo/subdir &&
git-svn fetch &&
git-svn commit-diff -r3 '$prev' '$head' &&
svn cat $svnrepo/subdir/readme > readme.2 &&
cmp readme readme.2
"

test_done

0 comments on commit d3a840d

Please sign in to comment.