git-svn: let 'dcommit $rev' work on $rev instead of HEAD

'git svn dcommit' takes an optional revision argument, but the meaning
of it was rather scary.  It completely ignored the current state of
the HEAD, only looking at the revisions between SVN and $rev.  If HEAD
was attached to $branch, the branch lost all commits $rev..$branch in
the process.

Considering that 'git svn dcommit HEAD^' has the intuitive meaning
"dcommit all changes on my branch except the last one", we change the
meaning of the revision argument.  git-svn temporarily checks out $rev
for its work, meaning that

* if a branch is specified, that branch (_not_ the HEAD) is rebased as
  part of the dcommit,

* if some other revision is specified, as in the example, all work
  happens on a detached HEAD and no branch is affected.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Acked-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
Thomas Rast
2009-05-29 17:09:42 +02:00
committed by Eric Wong
parent 916e1373fb
commit 5eec27e35f
3 changed files with 54 additions and 4 deletions

View File

@ -231,6 +231,25 @@ test_expect_success \
"^:refs/${remotes_git_svn}$"
'
test_expect_success 'dcommit $rev does not clobber current branch' '
git svn fetch -i bar &&
git checkout -b my-bar refs/remotes/bar &&
echo 1 > foo &&
git add foo &&
git commit -m "change 1" &&
echo 2 > foo &&
git add foo &&
git commit -m "change 2" &&
old_head=$(git rev-parse HEAD) &&
git svn dcommit -i bar HEAD^ &&
test $old_head = $(git rev-parse HEAD) &&
test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
git log refs/remotes/bar | grep "change 1" &&
! git log refs/remotes/bar | grep "change 2" &&
git checkout master &&
git branch -D my-bar
'
test_expect_success 'able to dcommit to a subdirectory' "
git svn fetch -i bar &&
git checkout -b my-bar refs/remotes/bar &&