[PATCH v4 1/4] t7501: add coverage for flags which imply dry runs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The behavior of git commit, when doing a dry run, changes if there are
unresolved/resolved merge conflicts, but the test suite currently only
asserts that `git commit --dry-run` succeeds when all merge conflicts
are resolved.

Add tests to document the behavior of all flags (i.e. `--dry-run`,
`--short`, `--porcelain`, and `--long`) which imply a dry run when (1)
there are only unresolved merge conflicts, (2) when there are both
unresolved and resolved merge conflicts, and (3) when all merge
conflicts are resolved.

When testing behavior involving resolved merge conflicts, resolve merge
conflicts by replacing each merge conflict with completely new contents,
rather than choosing the contents associated with one of the parent
commits, since the latter decision has no bearing on the behavior of a
dry run commit invocation.

Verify that a dry run invocation of git commit does not create a new
commit by asserting that HEAD has not changed, instead of by crafting
the commit.

Signed-off-by: Samuel Lijin <sxlijin@xxxxxxxxx>
---
 t/t7501-commit.sh | 146 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 132 insertions(+), 14 deletions(-)

diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 9dbbd01fc..e49dfd0a2 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -664,24 +664,142 @@ test_expect_success '--only works on to-be-born branch' '
 	test_cmp expected actual
 '
 
-test_expect_success '--dry-run with conflicts fixed from a merge' '
-	# setup two branches with conflicting information
-	# in the same file, resolve the conflict,
-	# call commit with --dry-run
-	echo "Initial contents, unimportant" >test-file &&
-	git add test-file &&
+test_expect_success 'prepare commits that can be used to trigger a merge conflict' '
+	# setup two branches with conflicting contents in two paths
+	echo "Initial contents, unimportant" | tee test-file1 test-file2 &&
+	git add test-file1 test-file2 &&
 	git commit -m "Initial commit" &&
-	echo "commit-1-state" >test-file &&
-	git commit -m "commit 1" -i test-file &&
+	echo "commit-1-state" | tee test-file1 test-file2 &&
+	git commit -m "commit 1" -i test-file1 test-file2 &&
 	git tag commit-1 &&
 	git checkout -b branch-2 HEAD^1 &&
-	echo "commit-2-state" >test-file &&
-	git commit -m "commit 2" -i test-file &&
-	! $(git merge --no-commit commit-1) &&
-	echo "commit-2-state" >test-file &&
-	git add test-file &&
+	echo "commit-2-state" | tee test-file1 test-file2 &&
+	git commit -m "commit 2" -i test-file1 test-file2 &&
+	git tag commit-2
+'
+
+test_expect_success '--dry-run with only unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	test_must_fail git commit --dry-run &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--short with only unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	test_must_fail git commit --short &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--porcelain with only unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	test_must_fail git commit --porcelain &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--long with only unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	test_must_fail git commit --long &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure '--dry-run with resolved and unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve one merge conflict" >test-file1 &&
+	git add test-file1 &&
+	test_must_fail git commit --dry-run &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--short with resolved and unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve one merge conflict" >test-file1 &&
+	git add test-file1 &&
+	test_must_fail git commit --short &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--porcelain with resolved and unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve one merge conflict" >test-file1 &&
+	git add test-file1 &&
+	test_must_fail git commit --porcelain &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure '--long with resolved and unresolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve one merge conflict" >test-file1 &&
+	git add test-file1 &&
+	test_must_fail git commit --long &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--dry-run with only resolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve all merge conflicts" | tee test-file1 test-file2 &&
+	git add test-file1 test-file2 &&
 	git commit --dry-run &&
-	git commit -m "conflicts fixed from merge."
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure '--short with only resolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve all merge conflicts" | tee test-file1 test-file2 &&
+	git add test-file1 test-file2 &&
+	git commit --short &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure '--porcelain with only resolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve all merge conflicts" | tee test-file1 test-file2 &&
+	git add test-file1 test-file2 &&
+	git commit --porcelain &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success '--long with only resolved merge conflicts' '
+	git reset --hard commit-2 &&
+	test_must_fail git merge --no-commit commit-1 &&
+	echo "resolve all merge conflicts" | tee test-file1 test-file2 &&
+	git add test-file1 test-file2 &&
+	git commit --long &&
+	git rev-parse commit-2 >expected &&
+	git rev-parse HEAD >actual &&
+	test_cmp expected actual
 '
 
 test_done
-- 
2.18.0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux