| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git ls-files --format test' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | for flag in -s -o -k -t --resolve-undo --deduplicate --eol |
| 8 | do |
| 9 | test_expect_success "usage: --format is incompatible with $flag" ' |
| 10 | test_expect_code 129 git ls-files --format="%(objectname)" $flag |
| 11 | ' |
| 12 | done |
| 13 | |
| 14 | test_expect_success 'setup' ' |
| 15 | printf "LINEONE\nLINETWO\nLINETHREE\n" >o1.txt && |
| 16 | printf "LINEONE\r\nLINETWO\r\nLINETHREE\r\n" >o2.txt && |
| 17 | printf "LINEONE\r\nLINETWO\nLINETHREE\n" >o3.txt && |
| 18 | git add o?.txt && |
| 19 | oid=$(git hash-object o1.txt) && |
| 20 | git update-index --add --cacheinfo 120000 $oid o4.txt && |
| 21 | git update-index --add --cacheinfo 160000 $oid o5.txt && |
| 22 | git update-index --add --cacheinfo 100755 $oid o6.txt && |
| 23 | git commit -m base |
| 24 | ' |
| 25 | |
| 26 | test_expect_success 'git ls-files --format objectmode v.s. -s' ' |
| 27 | git ls-files -s >files && |
| 28 | cut -d" " -f1 files >expect && |
| 29 | git ls-files --format="%(objectmode)" >actual && |
| 30 | test_cmp expect actual |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'git ls-files --format objectname v.s. -s' ' |
| 34 | git ls-files -s >files && |
| 35 | cut -d" " -f2 files >expect && |
| 36 | git ls-files --format="%(objectname)" >actual && |
| 37 | test_cmp expect actual |
| 38 | ' |
| 39 | |
| 40 | test_expect_success 'git ls-files --format objecttype' ' |
| 41 | git ls-files --format="%(objectname)" o1.txt o4.txt o6.txt >objectname && |
| 42 | git cat-file --batch-check="%(objecttype)" >expect <objectname && |
| 43 | git ls-files --format="%(objecttype)" o1.txt o4.txt o6.txt >actual && |
| 44 | test_cmp expect actual |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'git ls-files --format objectsize' ' |
| 48 | cat>expect <<-\EOF && |
| 49 | 26 |
| 50 | 29 |
| 51 | 27 |
| 52 | 26 |
| 53 | - |
| 54 | 26 |
| 55 | EOF |
| 56 | git ls-files --format="%(objectsize)" >actual && |
| 57 | |
| 58 | test_cmp expect actual |
| 59 | ' |
| 60 | |
| 61 | test_expect_success 'git ls-files --format objectsize:padded' ' |
| 62 | cat>expect <<-\EOF && |
| 63 | 26 |
| 64 | 29 |
| 65 | 27 |
| 66 | 26 |
| 67 | - |
| 68 | 26 |
| 69 | EOF |
| 70 | git ls-files --format="%(objectsize:padded)" >actual && |
| 71 | |
| 72 | test_cmp expect actual |
| 73 | ' |
| 74 | |
| 75 | test_expect_success 'git ls-files --format v.s. --eol' ' |
| 76 | git ls-files --eol >tmp && |
| 77 | sed -e "s/ / /g" -e "s/ */ /g" tmp >expect 2>err && |
| 78 | test_must_be_empty err && |
| 79 | git ls-files --format="i/%(eolinfo:index) w/%(eolinfo:worktree) attr/%(eolattr) %(path)" >actual 2>err && |
| 80 | test_must_be_empty err && |
| 81 | test_cmp expect actual |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'git ls-files --format path v.s. -s' ' |
| 85 | git ls-files -s >files && |
| 86 | cut -f2 files >expect && |
| 87 | git ls-files --format="%(path)" >actual && |
| 88 | test_cmp expect actual |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'git ls-files --format with relative path' ' |
| 92 | cat >expect <<-\EOF && |
| 93 | ../o1.txt |
| 94 | ../o2.txt |
| 95 | ../o3.txt |
| 96 | ../o4.txt |
| 97 | ../o5.txt |
| 98 | ../o6.txt |
| 99 | EOF |
| 100 | mkdir sub && |
| 101 | cd sub && |
| 102 | git ls-files --format="%(path)" ":/" >../actual && |
| 103 | cd .. && |
| 104 | test_cmp expect actual |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'git ls-files --format with -m' ' |
| 108 | echo change >o1.txt && |
| 109 | cat >expect <<-\EOF && |
| 110 | o1.txt |
| 111 | o4.txt |
| 112 | o5.txt |
| 113 | o6.txt |
| 114 | EOF |
| 115 | git ls-files --format="%(path)" -m >actual && |
| 116 | test_cmp expect actual |
| 117 | ' |
| 118 | |
| 119 | test_expect_success 'git ls-files --format with -d' ' |
| 120 | echo o7 >o7.txt && |
| 121 | git add o7.txt && |
| 122 | rm o7.txt && |
| 123 | cat >expect <<-\EOF && |
| 124 | o4.txt |
| 125 | o5.txt |
| 126 | o6.txt |
| 127 | o7.txt |
| 128 | EOF |
| 129 | git ls-files --format="%(path)" -d >actual && |
| 130 | test_cmp expect actual |
| 131 | ' |
| 132 | |
| 133 | test_expect_success 'git ls-files --format v.s -s' ' |
| 134 | git ls-files --stage >expect && |
| 135 | git ls-files --format="%(objectmode) %(objectname) %(stage)%x09%(path)" >actual && |
| 136 | test_cmp expect actual |
| 137 | ' |
| 138 | |
| 139 | test_expect_success 'git ls-files --format with --debug' ' |
| 140 | git ls-files --debug >expect && |
| 141 | git ls-files --format="%(path)" --debug >actual && |
| 142 | test_cmp expect actual |
| 143 | ' |
| 144 | |
| 145 | test_done |