git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@oracle.com>
To: git@vger.kernel.org
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Subject: [RFC PATCH 1/2] diff: add tests for git diff --merge/--ours/--theirs
Date: Wed, 15 Nov 2023 13:04:16 +0100	[thread overview]
Message-ID: <20231115120417.1327259-1-vegard.nossum@oracle.com> (raw)

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


             reply	other threads:[~2023-11-15 12:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-15 12:04 Vegard Nossum [this message]
2023-11-15 12:04 ` [RFC PATCH 2/2] rev-list: add --ours/--theirs options Vegard Nossum
2023-11-15 13:03   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231115120417.1327259-1-vegard.nossum@oracle.com \
    --to=vegard.nossum@oracle.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).