blob: e768c3eb2d48a9af2fc92729a6c20126f67ec866 [file] [log] [blame]
Charles Bailey05e934b2008-02-21 23:31:56 +00001#!/bin/sh
2#
3# Copyright (c) 2008 Charles Bailey
4#
5
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09006test_description='git mergetool
Charles Bailey05e934b2008-02-21 23:31:56 +00007
8Testing basic merge tool invocation'
9
10. ./test-lib.sh
11
Charles Baileyb9b50782009-01-30 23:20:10 +000012# All the mergetool test work by checking out a temporary branch based
13# off 'branch1' and then merging in master and checking the results of
14# running mergetool
15
Charles Bailey05e934b2008-02-21 23:31:56 +000016test_expect_success 'setup' '
17 echo master >file1 &&
Charles Baileyb9b50782009-01-30 23:20:10 +000018 mkdir subdir &&
19 echo master sub >subdir/file3 &&
20 git add file1 subdir/file3 &&
Charles Bailey05e934b2008-02-21 23:31:56 +000021 git commit -m "added file1" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000022
Charles Bailey05e934b2008-02-21 23:31:56 +000023 git checkout -b branch1 master &&
24 echo branch1 change >file1 &&
25 echo branch1 newfile >file2 &&
Charles Baileyb9b50782009-01-30 23:20:10 +000026 echo branch1 sub >subdir/file3 &&
27 git add file1 file2 subdir/file3 &&
Charles Bailey05e934b2008-02-21 23:31:56 +000028 git commit -m "branch1 changes" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000029
Charles Bailey05e934b2008-02-21 23:31:56 +000030 git checkout master &&
31 echo master updated >file1 &&
32 echo master new >file2 &&
Charles Baileyb9b50782009-01-30 23:20:10 +000033 echo master new sub >subdir/file3 &&
34 git add file1 file2 subdir/file3 &&
35 git commit -m "master updates" &&
36
37 git config merge.tool mytool &&
38 git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
39 git config mergetool.mytool.trustExitCode true
Charles Bailey05e934b2008-02-21 23:31:56 +000040'
41
42test_expect_success 'custom mergetool' '
Charles Baileyb9b50782009-01-30 23:20:10 +000043 git checkout -b test1 branch1 &&
Stephan Beyerd492b312008-07-12 17:47:52 +020044 test_must_fail git merge master >/dev/null 2>&1 &&
Charles Baileyb9b50782009-01-30 23:20:10 +000045 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
46 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
47 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
Charles Bailey05e934b2008-02-21 23:31:56 +000048 test "$(cat file1)" = "master updated" &&
49 test "$(cat file2)" = "master new" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000050 test "$(cat subdir/file3)" = "master new sub" &&
Charles Bailey0ec7b6c2009-01-21 22:57:48 +000051 git commit -m "branch1 resolved with mergetool"
52'
53
54test_expect_success 'mergetool crlf' '
55 git config core.autocrlf true &&
Charles Baileyb9b50782009-01-30 23:20:10 +000056 git checkout -b test2 branch1
Charles Bailey0ec7b6c2009-01-21 22:57:48 +000057 test_must_fail git merge master >/dev/null 2>&1 &&
Charles Baileyb9b50782009-01-30 23:20:10 +000058 ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
59 ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
60 ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
Charles Bailey0ec7b6c2009-01-21 22:57:48 +000061 test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
62 test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
Charles Baileyb9b50782009-01-30 23:20:10 +000063 test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
64 git commit -m "branch1 resolved with mergetool - autocrlf" &&
65 git config core.autocrlf false &&
66 git reset --hard
Charles Bailey05e934b2008-02-21 23:31:56 +000067'
68
Charles Baileyff4a1852009-01-30 23:20:11 +000069test_expect_success 'mergetool in subdir' '
Charles Baileyb9b50782009-01-30 23:20:10 +000070 git checkout -b test3 branch1
71 cd subdir && (
72 test_must_fail git merge master >/dev/null 2>&1 &&
73 ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
74 test "$(cat file3)" = "master new sub" )
75'
76
77# We can't merge files from parent directories when running mergetool
78# from a subdir. Is this a bug?
79#
80#test_expect_failure 'mergetool in subdir' '
81# cd subdir && (
82# ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
83# ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
84# test "$(cat ../file1)" = "master updated" &&
85# test "$(cat ../file2)" = "master new" &&
86# git commit -m "branch1 resolved with mergetool - subdir" )
87#'
88
Charles Bailey05e934b2008-02-21 23:31:56 +000089test_done