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

[RFC PATCH 1/2] diff: add tests for git diff --merge/--ours/--theirs

From
Vegard Nossum <vegard.nossum@oracle.com>
Date
Nov 15, 2023, 12:04 UTC
Message-ID
<20231115120417.1327259-1-vegard.nossum@oracle.com>

These options don't seem to have any tests currently and the next patch in this series changes how these options are parsed. Add tests.

Based loosely on t/t6417-merge-ours-theirs.sh.
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
 t/t4070-diff-merge.sh | 79 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100755 t/t4070-diff-merge.sh
diff --git a/t/t4070-diff-merge.sh b/t/t4070-diff-merge.sh
new file mode 100755
index 0000000000..01ac82f0c4
--- /dev/null
+++ b/t/t4070-diff-merge.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+test_description='git diff --merge/--ours/--theirs'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_write_lines initial >file &&
+	git add file &&
+	git commit -m initial &&
+
+	git checkout -b ours main &&
+	test_write_lines ours >file &&
+	git commit -a -m ours &&
+
+	git checkout -b theirs main &&
+	test_write_lines theirs >file &&
+	git commit -a -m theirs &&
+
+	git checkout ours^0 &&
+	test_must_fail git merge theirs &&
+
+	INITIAL=$(git rev-parse main) &&
+	OURS=$(git rev-parse ours) &&
+	THEIRS=$(git rev-parse theirs)
+'
+
+test_expect_success 'git diff --merge' '
+	git diff --merge | grep -v ^index >actual &&
+	cat >expect <<-\EOF &&
+	diff --cc file
+	--- a/file
+	+++ b/file
+	@@@ -1,1 -1,1 +1,1 @@@
+	- theirs
+	 -initial
+	++ours
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'git diff --ours' '
+	git diff --ours | grep -v ^index >actual &&
+	cat >expect <<-\EOF &&
+	* Unmerged path file
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1 +1,5 @@
+	+<<<<<<< HEAD
+	 ours
+	+=======
+	+theirs
+	+>>>>>>> theirs
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'git diff --theirs' '
+	git diff --theirs | grep -v ^index >actual &&
+	cat >expect <<-\EOF &&
+	* Unmerged path file
+	diff --git a/file b/file
+	--- a/file
+	+++ b/file
+	@@ -1 +1,5 @@
+	+<<<<<<< HEAD
+	+ours
+	+=======
+	 theirs
+	+>>>>>>> theirs
+	EOF
+	test_cmp expect actual
+'
+
+test_done
-- 
2.34.1
Next: Vegard Nossum
Message 1 of 3 in “diff: add tests for git diff --merge/--ours/--theirs”
  1. 1/2 diff: add tests for git diff --merge/--ours/--theirsVegard Nossum, Nov 15, 2023
  2. 2/2 rev-list: add --ours/--theirs optionsVegard Nossum, Nov 15, 2023
  3. Junio C HamanoNov 15, 2023

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.