t / t3902-quoted.shon commit Fix tests breaking when checkout path contains shell metacharacters (f69e836)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='quoted output'
   7
   8. ./test-lib.sh
   9
  10P1='pathname    with HT'
  11: >"$P1" 2>&1 && test -f "$P1" && rm -f "$P1" || {
  12        echo >&2 'Filesystem does not support HT in names'
  13        test_done
  14}
  15
  16FN='濱野'
  17GN='純'
  18HT='    '
  19LF='
  20'
  21DQ='"'
  22
  23echo foo > "Name and an${HT}HT"
  24test -f "Name and an${HT}HT" || {
  25        # since FAT/NTFS does not allow tabs in filenames, skip this test
  26        say 'Your filesystem does not allow tabs in filenames, test skipped.'
  27        test_done
  28}
  29
  30for_each_name () {
  31        for name in \
  32            Name "Name and a${LF}LF" "Name and an${HT}HT" "Name${DQ}" \
  33            "$FN$HT$GN" "$FN$LF$GN" "$FN $GN" "$FN$GN" "$FN$DQ$GN" \
  34            "With SP in it"
  35        do
  36                eval "$1"
  37        done
  38}
  39
  40test_expect_success setup '
  41
  42        for_each_name "echo initial >\"\$name\""
  43        git add . &&
  44        git commit -q -m Initial &&
  45
  46        for_each_name "echo second >\"\$name\"" &&
  47        git commit -a -m Second
  48
  49        for_each_name "echo modified >\"\$name\""
  50
  51'
  52
  53cat >expect.quoted <<\EOF
  54Name
  55"Name and a\nLF"
  56"Name and an\tHT"
  57"Name\""
  58With SP in it
  59"\346\277\261\351\207\216\t\347\264\224"
  60"\346\277\261\351\207\216\n\347\264\224"
  61"\346\277\261\351\207\216 \347\264\224"
  62"\346\277\261\351\207\216\"\347\264\224"
  63"\346\277\261\351\207\216\347\264\224"
  64EOF
  65
  66cat >expect.raw <<\EOF
  67Name
  68"Name and a\nLF"
  69"Name and an\tHT"
  70"Name\""
  71With SP in it
  72"濱野\t純"
  73"濱野\n純"
  74濱野 純
  75"濱野\"純"
  76濱野純
  77EOF
  78
  79test_expect_success 'check fully quoted output from ls-files' '
  80
  81        git ls-files >current && test_cmp expect.quoted current
  82
  83'
  84
  85test_expect_success 'check fully quoted output from diff-files' '
  86
  87        git diff --name-only >current &&
  88        test_cmp expect.quoted current
  89
  90'
  91
  92test_expect_success 'check fully quoted output from diff-index' '
  93
  94        git diff --name-only HEAD >current &&
  95        test_cmp expect.quoted current
  96
  97'
  98
  99test_expect_success 'check fully quoted output from diff-tree' '
 100
 101        git diff --name-only HEAD^ HEAD >current &&
 102        test_cmp expect.quoted current
 103
 104'
 105
 106test_expect_success 'setting core.quotepath' '
 107
 108        git config --bool core.quotepath false
 109
 110'
 111
 112test_expect_success 'check fully quoted output from ls-files' '
 113
 114        git ls-files >current && test_cmp expect.raw current
 115
 116'
 117
 118test_expect_success 'check fully quoted output from diff-files' '
 119
 120        git diff --name-only >current &&
 121        test_cmp expect.raw current
 122
 123'
 124
 125test_expect_success 'check fully quoted output from diff-index' '
 126
 127        git diff --name-only HEAD >current &&
 128        test_cmp expect.raw current
 129
 130'
 131
 132test_expect_success 'check fully quoted output from diff-tree' '
 133
 134        git diff --name-only HEAD^ HEAD >current &&
 135        test_cmp expect.raw current
 136
 137'
 138
 139test_done