diff mbox series

[v3,2/4] t3432: test rebase fast-forward behavior

Message ID 4da2fe9b0429e10821e1cb96b79500c749fc31be.1554151449.git.liu.denton@gmail.com (mailing list archive)
State New, archived
Headers show
Series rebase: teach rebase --keep-base | expand

Commit Message

Denton Liu April 1, 2019, 8:51 p.m. UTC
When rebase is run on a branch that can be fast-forwarded, this should
automatically be done. Create test to ensure this behavior happens.

There is one case that currently does not pass. In the case where a
feature and master have diverged, running "git rebase master... master"
causes a full rebase to happen even though a fast-forward should happen.
Mark this case as failure so we can fix it later.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t3432-rebase-fast-forward.sh | 59 ++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 t/t3432-rebase-fast-forward.sh
diff mbox series

Patch

diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
new file mode 100755
index 0000000000..3e6362dd9c
--- /dev/null
+++ b/t/t3432-rebase-fast-forward.sh
@@ -0,0 +1,59 @@ 
+#!/bin/sh
+#
+# Copyright (c) 2019 Denton Liu
+#
+
+test_description='ensure rebase fast-forwards commits when possible'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_commit A &&
+	test_commit B &&
+	test_commit C &&
+	test_commit D &&
+	git checkout -t -b side
+'
+
+test_rebase_same_head() {
+	status="$1" &&
+	shift &&
+	test_expect_$status "git rebase $@ with $changes is no-op" "
+		oldhead=\$(git rev-parse HEAD) &&
+		test_when_finished 'git reset --hard \$oldhead' &&
+		git rebase $@ &&
+		newhead=\$(git rev-parse HEAD) &&
+		test_cmp_rev \$oldhead \$newhead
+	"
+}
+
+changes='no changes'
+test_rebase_same_head success ''
+test_rebase_same_head success 'master'
+test_rebase_same_head success '--onto B B'
+test_rebase_same_head success '--onto B... B'
+test_rebase_same_head success '--onto master... master'
+
+test_expect_success 'add work to side' '
+	test_commit E
+'
+
+changes='our changes'
+test_rebase_same_head success ''
+test_rebase_same_head success 'master'
+test_rebase_same_head success '--onto B B'
+test_rebase_same_head success '--onto B... B'
+test_rebase_same_head success '--onto master... master'
+
+test_expect_success 'add work to upstream' '
+	git checkout master &&
+	test_commit F &&
+	git checkout side
+'
+
+changes='our and their changes'
+test_rebase_same_head success '--onto B B'
+test_rebase_same_head success '--onto B... B'
+test_rebase_same_head failure '--onto master... master'
+
+test_done