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

[PATCH 1/2] add tests for merge-index / merge-one-file

From
Jeff King <peff@peff.net>
Date
Apr 28, 2011, 22:39 UTC
Message-ID
<20110428223949.GA16027@sigill.intra.peff.net>
In-Reply-To
<20110428223822.GA16004@sigill.intra.peff.net>

There were no tests for either, except a brief use in t1200-tutorial.

These tools are not used much these days, as most people use the merge-recursive strategy, which handles everything internally. However, they are used by the "octopus" and "resolve" strategies, as well as any custom strategies or merge scripts people have built around them.

For example, together with read-tree, they are the simplest way to do a basic content-level merge without checking out the entire repository contents beforehand.

This script adds a basic test of the tools to perform one content-level merge. It also shows a failure of the tools to work properly in the face of GIT_WORK_TREE.

Signed-off-by: Jeff King <peff@peff.net>
---
We could also exercise the more exotic "both sides added" code paths of
merge-one-file. But anybody who cares about that these days is almost
certainly using "read-tree --aggressive" anyway.
 t/t6060-merge-index.sh |   70 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)
 create mode 100755 t/t6060-merge-index.sh
diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh
new file mode 100755
index 0000000..8f8ec77
--- /dev/null
+++ b/t/t6060-merge-index.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='basic git merge-index / git-merge-one-file tests'
+. ./test-lib.sh
+
+test_expect_success 'setup diverging branches' '
+	for i in 1 2 3 4 5 6 7 8 9 10; do
+		echo $i
+	done >file &&
+	git add file &&
+	git commit -m base &&
+	git tag base &&
+	sed s/2/two/ <file >tmp &&
+	mv tmp file &&
+	git commit -a -m two &&
+	git tag two &&
+	git checkout -b other HEAD^ &&
+	sed s/10/ten/ <file >tmp &&
+	mv tmp file &&
+	git commit -a -m ten &&
+	git tag ten
+'
+
+cat >expect-merged <<'EOF'
+1
+two
+3
+4
+5
+6
+7
+8
+9
+ten
+EOF
+
+test_expect_success 'read-tree does not resolve content merge' '
+	git read-tree -i -m base ten two &&
+	echo file >expect &&
+	git diff-files --name-only --diff-filter=U >unmerged &&
+	test_cmp expect unmerged
+'
+
+test_expect_success 'git merge-index git-merge-one-file resolves' '
+	git merge-index git-merge-one-file -a &&
+	git diff-files --name-only --diff-filter=U >unmerged &&
+	>expect &&
+	test_cmp expect unmerged &&
+	test_cmp expect-merged file &&
+	git cat-file blob :file >file-index &&
+	test_cmp expect-merged file-index
+'
+
+test_expect_failure 'merge-one-file respects GIT_WORK_TREE' '
+	git clone . bare.git &&
+	(cd bare.git &&
+	 mkdir work &&
+	 GIT_WORK_TREE=$PWD/work &&
+	 export GIT_WORK_TREE &&
+	 GIT_INDEX_FILE=$PWD/merge.index &&
+	 export GIT_INDEX_FILE &&
+	 git read-tree -i -m base ten two &&
+	 git merge-index git-merge-one-file -a &&
+	 git cat-file blob :file >work/file-index
+	) &&
+	test_cmp expect-merged bare.git/work/file &&
+	test_cmp expect-merged bare.git/work/file-index
+'
+
+test_done
-- 
1.7.5.rc3.17.g5e09b
Previous: Jeff KingNext: Johannes Sixt
Message 2 of 6 in “merge-one-file and GIT_WORK_TREE”
  1. 0/2 merge-one-file and GIT_WORK_TREEJeff King, Apr 28, 2011
  2. 1/2 add tests for merge-index / merge-one-fileJeff King, Apr 28, 2011
  3. Johannes SixtApr 29, 2011
  4. Junio C HamanoApr 29, 2011
  5. 2/2 merge-one-file: fix broken merges with GIT_WORK_TREEJeff King, Apr 28, 2011
  6. Junio C HamanoApr 29, 2011

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.