t / t7610-mergetool.shon commit Makefile: SunOS 5.6 portability fix (614dd90)
   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    echo master >file1 &&
  18    mkdir subdir &&
  19    echo master sub >subdir/file3 &&
  20    git add file1 subdir/file3 &&
  21    git commit -m "added file1" &&
  22
  23    git checkout -b branch1 master &&
  24    echo branch1 change >file1 &&
  25    echo branch1 newfile >file2 &&
  26    echo branch1 sub >subdir/file3 &&
  27    git add file1 file2 subdir/file3 &&
  28    git commit -m "branch1 changes" &&
  29
  30    git checkout master &&
  31    echo master updated >file1 &&
  32    echo master new >file2 &&
  33    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
  40'
  41
  42test_expect_success 'custom mergetool' '
  43    git checkout -b test1 branch1 &&
  44    test_must_fail git merge master >/dev/null 2>&1 &&
  45    ( 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 ) &&
  48    test "$(cat file1)" = "master updated" &&
  49    test "$(cat file2)" = "master new" &&
  50    test "$(cat subdir/file3)" = "master new sub" &&
  51    git commit -m "branch1 resolved with mergetool"
  52'
  53
  54test_expect_success 'mergetool crlf' '
  55    git config core.autocrlf true &&
  56    git checkout -b test2 branch1
  57    test_must_fail git merge master >/dev/null 2>&1 &&
  58    ( 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 ) &&
  61    test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
  62    test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
  63    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
  67'
  68
  69test_expect_success 'mergetool in subdir' '
  70    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
  89test_done