[PATCH 1/2] t7501: Add tests for various index usages, -i and -o, of commit command.

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

 



This commit adds tests for -i and -o flags of the commit command. It
includes testing -i with and without staged changes, testing -o with and
without staged changes, and testing -i and -o together.

Signed-off-by: Ghanshyam Thakkar <shyamthakkar001@xxxxxxxxx>
---
 t/t7501-commit-basic-functionality.sh | 90 +++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index 3d8500a52e..71dc52ce3a 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -76,6 +76,96 @@ test_expect_success 'nothing to commit' '
 	test_must_fail git commit -m initial
 '
 
+test_expect_success 'commit with -i fails with untracked files' '
+	test_when_finished "rm -rf testdir" &&
+	git init testdir &&
+	echo content >testdir/file.txt &&
+	test_must_fail git -C testdir commit -i file.txt -m initial
+'
+
+test_expect_success 'commit with -i' '
+	echo content >bar &&
+	git add bar &&
+	git commit -m "bar" &&
+
+	echo content2 >bar &&
+	git commit -i bar -m "bar second"
+'
+
+test_expect_success 'commit with -i multiple files' '
+	test_when_finished "git reset --hard" &&
+	echo content >bar &&
+	echo content >baz &&
+	echo content >saz &&
+	git add bar baz saz &&
+	git commit -m "bar baz saz" &&
+
+	echo content2 >bar &&
+	echo content2 >baz &&
+	echo content2 >saz &&
+	git commit -i bar saz -m "bar" &&
+	git diff --name-only >remaining &&
+	test_grep "baz" remaining
+'
+
+test_expect_success 'commit with -i includes staged changes' '
+	test_when_finished "git reset --hard" &&
+	echo content >bar &&
+	git add bar &&
+	git commit -m "bar" &&
+
+	echo content2 >bar &&
+	echo content2 >baz &&
+	git add baz &&
+	git commit -i bar -m "bar baz" &&
+	git diff --name-only >remaining &&
+	test_must_be_empty remaining &&
+	git diff --name-only --staged >remaining &&
+	test_must_be_empty remaining
+'
+
+test_expect_success 'commit with -o' '
+	echo content >bar &&
+	git add bar &&
+	git commit -m "bar" &&
+	echo content2 >bar &&
+	git commit -o bar -m "bar again"
+'
+
+test_expect_success 'commit with -o fails with untracked files' '
+	test_when_finished "rm -rf testdir" &&
+	git init testdir &&
+	echo content >testdir/bar &&
+	test_must_fail git -C testdir commit -o bar -m "bar"
+'
+
+test_expect_success 'commit with -o exludes staged changes' '
+	test_when_finished "git reset --hard" &&
+	echo content >bar &&
+	echo content >baz &&
+	git add . &&
+	git commit -m "bar baz" &&
+
+	echo content2 >bar &&
+	echo content2 >baz &&
+	git add baz &&
+	git commit -o bar -m "bar" &&
+	git diff --name-only --staged >actual &&
+	test_grep "baz" actual
+'
+
+test_expect_success 'commit with both -i and -o fails' '
+	test_when_finished "git reset --hard" &&
+	echo content >bar &&
+	echo content >baz &&
+	git add . &&
+	git commit -m "bar baz" &&
+
+	echo content2 >bar &&
+	echo content2 >baz &&
+	test_must_fail git commit -i baz -o bar -m "bar"
+'
+
 test_expect_success '--dry-run fails with nothing to commit' '
 	test_must_fail git commit -m initial --dry-run
 '
-- 
2.43.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