Merge branch 'rr/rebase-sha1-by-string-query'

Allow various commit objects to be given to "git rebase" by ':/look
for this string' syntax, e.g. "git rebase --onto ':/there'".

* rr/rebase-sha1-by-string-query:
  rebase: use peel_committish() where appropriate
  sh-setup: add new peel_committish() helper
  t/rebase: add failing tests for a peculiar revision
This commit is contained in:
Junio C Hamano 2013-06-24 13:48:40 -07:00
commit bc918acf70
4 changed files with 36 additions and 2 deletions

View file

@ -436,7 +436,7 @@ then
shift
;;
esac
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
upstream=$(peel_committish "${upstream_name}") ||
die "$(eval_gettext "invalid upstream \$upstream_name")"
upstream_arg="$upstream_name"
else
@ -472,7 +472,7 @@ case "$onto_name" in
fi
;;
*)
onto=$(git rev-parse --verify "${onto_name}^0") ||
onto=$(peel_committish "$onto_name") ||
die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
;;
esac

View file

@ -313,3 +313,15 @@ then
}
: ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
fi
peel_committish () {
case "$1" in
:/*)
peeltmp=$(git rev-parse --verify "$1") &&
git rev-parse --verify "${peeltmp}^0"
;;
*)
git rev-parse --verify "${1}^0"
;;
esac
}

View file

@ -59,6 +59,17 @@ test_expect_success 'rebase against master' '
git rebase master
'
test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
test_when_finished "git branch -D torebase" &&
git checkout -b torebase my-topic-branch^ &&
upstream=$(git rev-parse ":/Add B") &&
onto=$(git rev-parse ":/Add A") &&
git rebase --onto $onto $upstream &&
git reset --hard my-topic-branch^ &&
git rebase --onto ":/Add A" ":/Add B" &&
git checkout my-topic-branch
'
test_expect_success 'the rebase operation should not have destroyed author information' '
! (git log | grep "Author:" | grep "<>")
'

View file

@ -939,4 +939,15 @@ test_expect_success 'rebase -i respects core.commentchar' '
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
'
test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
test_when_finished "git branch -D torebase" &&
git checkout -b torebase branch1 &&
upstream=$(git rev-parse ":/J") &&
onto=$(git rev-parse ":/A") &&
git rebase --onto $onto $upstream &&
git reset --hard branch1 &&
git rebase --onto ":/A" ":/J" &&
git checkout branch1
'
test_done