t / t4011-diff-symlink.shon commit Merge branch 'maint' (d6096f1)
   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 \
  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 \
  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 \
  50    'diff removed symlink' \
  51    'rm frotz &&
  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 \
  60    'diff identical, but newly created symlink' \
  61    'sleep 3 &&
  62    ln -s xyzzy frotz &&
  63    git diff-index -M -p $tree > current &&
  64    compare_diff_patch current expected'
  65
  66cat > expected << EOF
  67diff --git a/frotz b/frotz
  68index 7c465af..df1db54 120000
  69--- a/frotz
  70+++ b/frotz
  71@@ -1 +1 @@
  72-xyzzy
  73\ No newline at end of file
  74+yxyyz
  75\ No newline at end of file
  76EOF
  77
  78test_expect_success \
  79    'diff different symlink' \
  80    'rm frotz &&
  81    ln -s yxyyz frotz &&
  82    git diff-index -M -p $tree > current &&
  83    compare_diff_patch current expected'
  84
  85test_done