aboutsummaryrefslogtreecommitdiff
path: root/t/t6026-merge-attr.sh
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-04-17 22:51:45 -0700
committerJunio C Hamano <junkio@cox.net>2007-04-18 01:43:42 -0700
commitf3ef6b6bbe9bfd3d09130f7e26b87dbe11b93c5b (patch)
tree4dff356b896dfa2ddacdaff0e3c9ff06f8f0b91e /t/t6026-merge-attr.sh
parent47579efc009c6f7afaf31be107eb92395a4f10db (diff)
downloadgit-f3ef6b6bbe9bfd3d09130f7e26b87dbe11b93c5b.tar.gz
git-f3ef6b6bbe9bfd3d09130f7e26b87dbe11b93c5b.tar.xz
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per path, using the attributes mechanism. Just like you can specify one of built-in "text", "binary", "union" low-level merge drivers by saying: * merge=text .gitignore merge=union *.jpg merge=binary pick a name of your favorite merge driver, and assign it as the value of the 'merge' attribute. A custom low-level merge driver is defined via the config mechanism. This patch introduces 'merge.driver', a multi-valued configuration. Its value is the name (i.e. the one you use as the value of 'merge' attribute) followed by a command line specification. The command line can contain %O, %A, and %B to be interpolated with the names of temporary files that hold the common ancestor version, the version from your branch, and the version from the other branch, and the resulting command is spawned. The low-level merge driver is expected to update the temporary file for your branch (i.e. %A) with the result and exit with status 0 for a clean merge, and non-zero status for a conflicted merge. A new test in t6026 demonstrates a sample usage. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 't/t6026-merge-attr.sh')
-rwxr-xr-xt/t6026-merge-attr.sh71
1 files changed, 70 insertions, 1 deletions
diff --git a/t/t6026-merge-attr.sh b/t/t6026-merge-attr.sh
index 5daa2236d..1732b60ed 100755
--- a/t/t6026-merge-attr.sh
+++ b/t/t6026-merge-attr.sh
@@ -30,8 +30,9 @@ test_expect_success setup '
echo Side >>$f && git add $f || break
done &&
test_tick &&
- git commit -m Side
+ git commit -m Side &&
+ git tag anchor
'
test_expect_success merge '
@@ -69,4 +70,72 @@ test_expect_success 'check merge result in working tree' '
'
+cat >./custom-merge <<\EOF
+#!/bin/sh
+
+orig="$1" ours="$2" theirs="$3" exit="$4"
+(
+ echo "orig is $orig"
+ echo "ours is $ours"
+ echo "theirs is $theirs"
+ echo "=== orig ==="
+ cat "$orig"
+ echo "=== ours ==="
+ cat "$ours"
+ echo "=== theirs ==="
+ cat "$theirs"
+) >"$ours+"
+cat "$ours+" >"$ours"
+rm -f "$ours+"
+exit "$exit"
+EOF
+chmod +x ./custom-merge
+
+test_expect_success 'custom merge backend' '
+
+ echo "* merge=union" >.gitattributes &&
+ echo "text merge=custom" >>.gitattributes &&
+
+ git reset --hard anchor &&
+ git config --replace-all \
+ merge.driver "custom ./custom-merge %O %A %B 0" &&
+
+ git merge master &&
+
+ cmp binary union &&
+ sed -e 1,3d text >check-1 &&
+ o=$(git-unpack-file master^:text) &&
+ a=$(git-unpack-file side^:text) &&
+ b=$(git-unpack-file master:text) &&
+ sh -c "./custom-merge $o $a $b 0" &&
+ sed -e 1,3d $a >check-2 &&
+ cmp check-1 check-2 &&
+ rm -f $o $a $b
+'
+
+test_expect_success 'custom merge backend' '
+
+ git reset --hard anchor &&
+ git config --replace-all \
+ merge.driver "custom ./custom-merge %O %A %B 1" &&
+
+ if git merge master
+ then
+ echo "Eh? should have conflicted"
+ false
+ else
+ echo "Ok, conflicted"
+ fi &&
+
+ cmp binary union &&
+ sed -e 1,3d text >check-1 &&
+ o=$(git-unpack-file master^:text) &&
+ a=$(git-unpack-file anchor:text) &&
+ b=$(git-unpack-file master:text) &&
+ sh -c "./custom-merge $o $a $b 0" &&
+ sed -e 1,3d $a >check-2 &&
+ cmp check-1 check-2 &&
+ rm -f $o $a $b
+'
+
test_done