Support :/quuxery in rebase (early preview)
cover Support :/quuxery in rebase (early preview)
Hi,
So this is a series to make git rebase [-i] :/quuxery possible. It is an early preview, because I have not tested that :/quuxery works as the <onto>, <upstream>, and <branch>.
Thanks.
Ramkumar Ramachandra (3):
t/rebase: add failing tests for a peculiar revision
sh-setup: add new peel_committish() helper
rebase: use peel_committish() where appropriate
git-rebase.sh | 6 +++--- git-sh-setup.sh | 13 +++++++++++++ t/t3400-rebase.sh | 8 ++++++++ t/t3404-rebase-interactive.sh | 8 ++++++++ 4 files changed, 32 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1.381.g31c8856.dirty
PATCH 1/3 t/rebase: add failing tests for a peculiar revision
The following commands fail, even if :/quuxery resolves to a perfectly valid commit:
$ git rebase :/quuxery $ git rebase -i :/quuxery
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.
--- t/t3400-rebase.sh | 8 ++++++++ t/t3404-rebase-interactive.sh | 8 ++++++++ 2 files changed, 16 insertions(+)
t/t3400-rebase.sh +8 -0
@@ -88,6 +88,14 @@ test_expect_success 'rebase fast-forward to master' ' test_i18ngrep "Fast-forwarded HEAD to my-topic-branch" out ' +test_expect_failure 'rebase against revision specified as :/quuxery' ' + git checkout my-topic-branch^ && + sha1=$(git rev-parse ":/Add B") && + git rebase $sha1 && + git checkout my-topic-branch^ && + git rebase ":/Add B" +' + test_expect_success 'the rebase operation should not have destroyed author information' ' ! (git log | grep "Author:" | grep "<>") '
t/t3404-rebase-interactive.sh +8 -0
@@ -947,4 +947,12 @@ test_expect_success 'rebase -i respects core.commentchar' ' test B = $(git cat-file commit HEAD^ | sed -ne \$p) ' +test_expect_failure 'rebase -i against revision specified as :/quuxery' ' + git checkout branch1 && + sha1=$(git rev-parse ":/J") && + git rebase $sha1 && + git checkout branch1 && + git rebase ":/J" +' + test_done
Signature · 1 line
1.8.3.1.381.g31c8856.dirty
PATCH 2/3 sh-setup: add new peel_committish() helper
In reply to Ramkumar RamachandraThe 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.
--- git-sh-setup.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+)
git-sh-setup.sh +13 -0
@@ -313,3 +313,16 @@ then } : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} fi + +peel_committish () { + test $# -gt 1 && quiet="--quiet" || quiet="" + case "$1" in + :/*) + peeltmp=$(git rev-parse --verify $quiet "$1") && + git rev-parse --verify "${peeltmp}^0" + ;; + *) + git rev-parse --verify "${1}^0" + ;; + esac +}
Signature · 1 line
1.8.3.1.381.g31c8856.dirty
PATCH 3/3 rebase: use peel_committish() where appropriate
In reply to Ramkumar RamachandraThe failing tests in t/rebase and t/rebase-interactive pass as a result.
--- git-rebase.sh | 6 +++--- t/t3400-rebase.sh | 2 +- t/t3404-rebase-interactive.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
git-rebase.sh +3 -3
@@ -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
@@ -490,7 +490,7 @@ case "$#" in orig_head=$(git rev-parse -q --verify "refs/heads/$1") then head_name="refs/heads/$1" - elif orig_head=$(git rev-parse -q --verify "$1") + elif orig_head=$(peel_committish "$1" quiet) then head_name="detached HEAD" else
t/t3400-rebase.sh +1 -1
@@ -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 against revision specified as :/quuxery' ' +test_expect_success 'rebase against revision specified as :/quuxery' ' git checkout my-topic-branch^ && sha1=$(git rev-parse ":/Add B") && git rebase $sha1 &&
t/t3404-rebase-interactive.sh +1 -1
@@ -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 against revision specified as :/quuxery' ' +test_expect_success 'rebase -i against revision specified as :/quuxery' ' git checkout branch1 && sha1=$(git rev-parse ":/J") && git rebase $sha1 &&
Signature · 1 line
1.8.3.1.381.g31c8856.dirty