[PATCH 0/3] Support :/quuxery in rebase (early preview)

DORMANTno replies

4 messages, 1 author, 2016-06-15 · open the first message on its own page

[PATCH 0/3] Support :/quuxery in rebase (early preview)

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:57:44

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(-)

-- 
1.8.3.1.381.g31c8856.dirty

[PATCH 1/3] t/rebase: add failing tests for a peculiar revision

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:57:44

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.

Signed-off-by: Ramkumar Ramachandra <redacted>
---
 t/t3400-rebase.sh             | 8 ++++++++
 t/t3404-rebase-interactive.sh | 8 ++++++++
 2 files changed, 16 insertions(+)
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index b58fa1a..890f159 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -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 "<>")
 '
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 79e8d3c..ca4ee92 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -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
-- 
1.8.3.1.381.g31c8856.dirty

[PATCH 2/3] sh-setup: add new peel_committish() helper

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:57:44

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 <redacted>
Signed-off-by: Ramkumar Ramachandra <redacted>
---
 git-sh-setup.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 2f78359..6ae19a6 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -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
+}
-- 
1.8.3.1.381.g31c8856.dirty

[PATCH 3/3] rebase: use peel_committish() where appropriate

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:57:44

The failing tests in t/rebase and t/rebase-interactive pass as a result.

Signed-off-by: Ramkumar Ramachandra <redacted>
---
 git-rebase.sh                 | 6 +++---
 t/t3400-rebase.sh             | 2 +-
 t/t3404-rebase-interactive.sh | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index d0c11a9..28e8d47 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
@@ -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
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 890f159..272f0f5 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 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 &&
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ca4ee92..c9a5d56 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 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 &&
-- 
1.8.3.1.381.g31c8856.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help