t / t7610-mergetool.shon commit Merge branch 'tc/checkout-B' (07cd900)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Charles Bailey
   4#
   5
   6test_description='git mergetool
   7
   8Testing basic merge tool invocation'
   9
  10. ./test-lib.sh
  11
  12# 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
  16test_expect_success 'setup' '
  17    git config rerere.enabled true &&
  18    echo master >file1 &&
  19    mkdir subdir &&
  20    echo master sub >subdir/file3 &&
  21    git add file1 subdir/file3 &&
  22    git commit -m "added file1" &&
  23
  24    git checkout -b branch1 master &&
  25    echo branch1 change >file1 &&
  26    echo branch1 newfile >file2 &&
  27    echo branch1 sub >subdir/file3 &&
  28    git add file1 file2 subdir/file3 &&
  29    git commit -m "branch1 changes" &&
  30
  31    git checkout master &&
  32    echo master updated >file1 &&
  33    echo master new >file2 &&
  34    echo master new sub >subdir/file3 &&
  35    git add file1 file2 subdir/file3 &&
  36    git commit -m "master updates" &&
  37
  38    git config merge.tool mytool &&
  39    git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
  40    git config mergetool.mytool.trustExitCode true
  41'
  42
  43test_expect_success 'custom mergetool' '
  44    git checkout -b test1 branch1 &&
  45    test_must_fail git merge master >/dev/null 2>&1 &&
  46    ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
  47    ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
  48    ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
  49    test "$(cat file1)" = "master updated" &&
  50    test "$(cat file2)" = "master new" &&
  51    test "$(cat subdir/file3)" = "master new sub" &&
  52    git commit -m "branch1 resolved with mergetool"
  53'
  54
  55test_expect_success 'mergetool crlf' '
  56    git config core.autocrlf true &&
  57    git checkout -b test2 branch1
  58    test_must_fail git merge master >/dev/null 2>&1 &&
  59    ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
  60    ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
  61    ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
  62    test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
  63    test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
  64    test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
  65    git commit -m "branch1 resolved with mergetool - autocrlf" &&
  66    git config core.autocrlf false &&
  67    git reset --hard
  68'
  69
  70test_expect_success 'mergetool in subdir' '
  71    git checkout -b test3 branch1
  72    cd subdir && (
  73    test_must_fail git merge master >/dev/null 2>&1 &&
  74    ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
  75    test "$(cat file3)" = "master new sub") &&
  76    cd ..
  77'
  78
  79test_expect_success 'mergetool on file in parent dir' '
  80    cd subdir && (
  81    ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
  82    ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
  83    test "$(cat ../file1)" = "master updated" &&
  84    test "$(cat ../file2)" = "master new" &&
  85    git commit -m "branch1 resolved with mergetool - subdir") &&
  86    cd ..
  87'
  88
  89test_expect_success 'mergetool skips autoresolved' '
  90    git checkout -b test4 branch1 &&
  91    test_must_fail git merge master &&
  92    test -n "$(git ls-files -u)" &&
  93    output="$(git mergetool --no-prompt)" &&
  94    test "$output" = "No files need merging" &&
  95    git reset --hard
  96'
  97
  98test_expect_success 'mergetool merges all from subdir' '
  99    cd subdir && (
 100    git config rerere.enabled false &&
 101    test_must_fail git merge master &&
 102    git mergetool --no-prompt &&
 103    test "$(cat ../file1)" = "master updated" &&
 104    test "$(cat ../file2)" = "master new" &&
 105    test "$(cat file3)" = "master new sub" &&
 106    git add ../file1 ../file2 file3 &&
 107    git commit -m "branch2 resolved by mergetool from subdir") &&
 108    cd ..
 109'
 110
 111test_done