t / t4011-diff-symlink.shon commit Sync with maint (65da088)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5
   6test_description='Test diff of symlinks.
   7
   8'
   9. ./test-lib.sh
  10. "$TEST_DIRECTORY"/diff-lib.sh
  11
  12cat > expected << EOF
  13diff --git a/frotz b/frotz
  14new file mode 120000
  15index 0000000..7c465af
  16--- /dev/null
  17+++ b/frotz
  18@@ -0,0 +1 @@
  19+xyzzy
  20\ No newline at end of file
  21EOF
  22
  23test_expect_success SYMLINKS \
  24    'diff new symlink' \
  25    'ln -s xyzzy frotz &&
  26    git update-index &&
  27    tree=$(git write-tree) &&
  28    git update-index --add frotz &&
  29    GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree > current &&
  30    compare_diff_patch current expected'
  31
  32test_expect_success SYMLINKS \
  33    'diff unchanged symlink' \
  34    'tree=$(git write-tree) &&
  35    git update-index frotz &&
  36    test -z "$(git diff-index --name-only $tree)"'
  37
  38cat > expected << EOF
  39diff --git a/frotz b/frotz
  40deleted file mode 120000
  41index 7c465af..0000000
  42--- a/frotz
  43+++ /dev/null
  44@@ -1 +0,0 @@
  45-xyzzy
  46\ No newline at end of file
  47EOF
  48
  49test_expect_success SYMLINKS \
  50    'diff removed symlink' \
  51    'mv frotz frotz2 &&
  52    git diff-index -M -p $tree > current &&
  53    compare_diff_patch current expected'
  54
  55cat > expected << EOF
  56diff --git a/frotz b/frotz
  57EOF
  58
  59test_expect_success SYMLINKS \
  60    'diff identical, but newly created symlink' \
  61    'ln -s xyzzy frotz &&
  62    git diff-index -M -p $tree > current &&
  63    compare_diff_patch current expected'
  64
  65cat > expected << EOF
  66diff --git a/frotz b/frotz
  67index 7c465af..df1db54 120000
  68--- a/frotz
  69+++ b/frotz
  70@@ -1 +1 @@
  71-xyzzy
  72\ No newline at end of file
  73+yxyyz
  74\ No newline at end of file
  75EOF
  76
  77test_expect_success SYMLINKS \
  78    'diff different symlink' \
  79    'rm frotz &&
  80    ln -s yxyyz frotz &&
  81    git diff-index -M -p $tree > current &&
  82    compare_diff_patch current expected'
  83
  84test_expect_success SYMLINKS \
  85    'diff symlinks with non-existing targets' \
  86    'ln -s narf pinky &&
  87    ln -s take\ over brain &&
  88    test_must_fail git diff --no-index pinky brain > output 2> output.err &&
  89    grep narf output &&
  90    ! grep error output.err'
  91
  92test_expect_success SYMLINKS 'setup symlinks with attributes' '
  93        echo "*.bin diff=bin" >>.gitattributes &&
  94        echo content >file.bin &&
  95        ln -s file.bin link.bin &&
  96        git add -N file.bin link.bin
  97'
  98
  99cat >expect <<'EOF'
 100diff --git a/file.bin b/file.bin
 101index e69de29..d95f3ad 100644
 102Binary files a/file.bin and b/file.bin differ
 103diff --git a/link.bin b/link.bin
 104index e69de29..dce41ec 120000
 105--- a/link.bin
 106+++ b/link.bin
 107@@ -0,0 +1 @@
 108+file.bin
 109\ No newline at end of file
 110EOF
 111test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
 112        git config diff.bin.binary true &&
 113        git diff file.bin link.bin >actual &&
 114        test_cmp expect actual
 115'
 116
 117test_done