git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Date
Jan 9, 2024, 06:04 UTC
Message-ID
<20240109060417.1144647-3-shyamthakkar001@gmail.com>
In-Reply-To
<20240109060417.1144647-2-shyamthakkar001@gmail.com>

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@gmail.com>
---
 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
Previous: Ghanshyam ThakkarNext: Christian Couder
Message 2 of 37 in “[GSOC] t7501: Add tests for various index usages, -i and -o, of commit command and amending commit to add signoff.”
  1. 0/2 [GSOC] t7501: Add tests for various index usages, -i and -o, of commit command and amending commit to add signoff.Ghanshyam Thakkar, Jan 9, 2024
  2. 1/2 t7501: Add tests for various index usages, -i and -o, of commit command.Ghanshyam Thakkar, Jan 9, 2024
  3. Christian CouderJan 9, 2024
  4. Ghanshyam ThakkarJan 9, 2024
  5. Junio C HamanoJan 9, 2024
  6. 2/2 t7501: Add test for amending commit to add signoff.Ghanshyam Thakkar, Jan 9, 2024
  7. Phillip WoodJan 9, 2024
  8. Ghanshyam ThakkarJan 9, 2024
  9. Junio C HamanoJan 9, 2024
  10. Christian CouderJan 9, 2024
  11. 0/2 t7501: add tests for --include, --only,Ghanshyam Thakkar, Jan 9, 2024
  12. 0/2 t7501: add tests for --include, --only andGhanshyam Thakkar, Jan 10, 2024
  13. 0/2 t7501: add tests for --include, --only, --signoffGhanshyam Thakkar, Jan 12, 2024
  14. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 12, 2024
  15. Junio C HamanoJan 12, 2024
  16. Ghanshyam ThakkarJan 13, 2024
  17. Junio C HamanoJan 13, 2024
  18. Ghanshyam ThakkarJan 13, 2024
  19. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 12, 2024
  20. 0/2 t7501: add tests for --include, --only, --signoffGhanshyam Thakkar, Jan 13, 2024
  21. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 13, 2024
  22. Junio C HamanoJan 16, 2024
  23. Junio C HamanoJan 16, 2024
  24. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 13, 2024
  25. 0/2 t7501: add tests for --include, --only, --signoffGhanshyam Thakkar, Jan 17, 2024
  26. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 17, 2024
  27. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 17, 2024
  28. Junio C HamanoJan 17, 2024
  29. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 10, 2024
  30. Junio C HamanoJan 10, 2024
  31. Ghanshyam ThakkarJan 11, 2024
  32. phillip.wood123@gmail.comJan 11, 2024
  33. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 10, 2024
  34. phillip.wood123@gmail.comJan 11, 2024
  35. 1/2 t7501: add tests for --include, --only of commitGhanshyam Thakkar, Jan 9, 2024
  36. Junio C HamanoJan 9, 2024
  37. 2/2 t7501: add test for --amend with --signoffGhanshyam Thakkar, Jan 9, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.