From 6567dc05a34948b959864b12fcd59a35543273f7 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Fri, 14 Jun 2013 18:47:50 +0530 Subject: t/rebase: add failing tests for a peculiar revision The following commands fail, even if :/quuxery and :/foomery resolve to perfectly valid commits: $ git rebase [-i] --onto :/quuxery :/foomery This is because rebase [-i] attempts to rev-parse ${REV}^0 to verify that the given revision resolves to a commit. Add tests to document these failures. Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- t/t3400-rebase.sh | 11 +++++++++++ t/t3404-rebase-interactive.sh | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index b58fa1a23..81ec51762 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -88,6 +88,17 @@ test_expect_success 'rebase fast-forward to master' ' test_i18ngrep "Fast-forwarded HEAD to my-topic-branch" out ' +test_expect_failure 'rebase, with and 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 "<>") ' diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 79e8d3c59..eb241f531 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -947,4 +947,15 @@ test_expect_success 'rebase -i respects core.commentchar' ' test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' +test_expect_failure 'rebase -i, with and 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 -- cgit v1.2.1 From bac1ddd0f86bc5955c24f89e402de80d2844efb5 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Fri, 14 Jun 2013 18:47:51 +0530 Subject: sh-setup: add new peel_committish() helper The normal way to check whether a certain revision resolves to a valid commit is: $ git rev-parse --verify $REV^0 Unfortunately, this does not work when $REV is of the type :/quuxery. Write a helper to work around this limitation. Suggested-by: Junio C Hamano Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- git-sh-setup.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 2f7835941..7a964ad2f 100644 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -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 +} -- cgit v1.2.1 From 2e6e276decde2a9f04fc29bce734a49d3ba8f484 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Fri, 14 Jun 2013 18:47:52 +0530 Subject: rebase: use peel_committish() where appropriate The revisions specified on the command-line as and arguments could be of the form :/quuxery; so, use peel_committish() to resolve them. The failing tests in t/rebase and t/rebase-interactive now pass. Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- git-rebase.sh | 4 ++-- t/t3400-rebase.sh | 2 +- t/t3404-rebase-interactive.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index d0c11a910..6987b9b6d 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -434,7 +434,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 @@ -470,7 +470,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 diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 81ec51762..cbca71ed5 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -88,7 +88,7 @@ test_expect_success 'rebase fast-forward to master' ' test_i18ngrep "Fast-forwarded HEAD to my-topic-branch" out ' -test_expect_failure 'rebase, with and specified as :/quuxery' ' +test_expect_success 'rebase, with and specified as :/quuxery' ' test_when_finished "git branch -D torebase" && git checkout -b torebase my-topic-branch^ && upstream=$(git rev-parse ":/Add B") && diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index eb241f531..86917d172 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -947,7 +947,7 @@ test_expect_success 'rebase -i respects core.commentchar' ' test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' -test_expect_failure 'rebase -i, with and specified as :/quuxery' ' +test_expect_success 'rebase -i, with and specified as :/quuxery' ' test_when_finished "git branch -D torebase" && git checkout -b torebase branch1 && upstream=$(git rev-parse ":/J") && -- cgit v1.2.1