t / t4011-diff-symlink.shon commit Merge branch 'js/maint-diff-temp-smudge' (b71fdc5)
   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
  12if ! test_have_prereq SYMLINKS
  13then
  14        say 'Symbolic links not supported, skipping tests.'
  15        test_done
  16        exit
  17fi
  18
  19cat > expected << EOF
  20diff --git a/frotz b/frotz
  21new file mode 120000
  22index 0000000..7c465af
  23--- /dev/null
  24+++ b/frotz
  25@@ -0,0 +1 @@
  26+xyzzy
  27\ No newline at end of file
  28EOF
  29
  30test_expect_success \
  31    'diff new symlink' \
  32    'ln -s xyzzy frotz &&
  33    git update-index &&
  34    tree=$(git write-tree) &&
  35    git update-index --add frotz &&
  36    GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree > current &&
  37    compare_diff_patch current expected'
  38
  39test_expect_success \
  40    'diff unchanged symlink' \
  41    'tree=$(git write-tree) &&
  42    git update-index frotz &&
  43    test -z "$(git diff-index --name-only $tree)"'
  44
  45cat > expected << EOF
  46diff --git a/frotz b/frotz
  47deleted file mode 120000
  48index 7c465af..0000000
  49--- a/frotz
  50+++ /dev/null
  51@@ -1 +0,0 @@
  52-xyzzy
  53\ No newline at end of file
  54EOF
  55
  56test_expect_success \
  57    'diff removed symlink' \
  58    'rm frotz &&
  59    git diff-index -M -p $tree > current &&
  60    compare_diff_patch current expected'
  61
  62cat > expected << EOF
  63diff --git a/frotz b/frotz
  64EOF
  65
  66test_expect_success \
  67    'diff identical, but newly created symlink' \
  68    'sleep 3 &&
  69    ln -s xyzzy frotz &&
  70    git diff-index -M -p $tree > current &&
  71    compare_diff_patch current expected'
  72
  73cat > expected << EOF
  74diff --git a/frotz b/frotz
  75index 7c465af..df1db54 120000
  76--- a/frotz
  77+++ b/frotz
  78@@ -1 +1 @@
  79-xyzzy
  80\ No newline at end of file
  81+yxyyz
  82\ No newline at end of file
  83EOF
  84
  85test_expect_success \
  86    'diff different symlink' \
  87    'rm frotz &&
  88    ln -s yxyyz frotz &&
  89    git diff-index -M -p $tree > current &&
  90    compare_diff_patch current expected'
  91
  92test_expect_success \
  93    'diff symlinks with non-existing targets' \
  94    'ln -s narf pinky &&
  95    ln -s take\ over brain &&
  96    test_must_fail git diff --no-index pinky brain > output 2> output.err &&
  97    grep narf output &&
  98    ! grep error output.err'
  99test_done