summaryrefslogtreecommitdiff
path: root/t/t3013-ls-files-format.sh
diff options
context:
space:
mode:
authorZheNing Hu <adlternative@gmail.com>2022-07-23 06:44:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-07-23 17:53:55 (GMT)
commitce74de931d7aea9746e37632534eacc63b0c1a90 (patch)
tree055af157523150f26dd169a7ccedae71f9aa876a /t/t3013-ls-files-format.sh
parent8168d5e9c23ed44ae3d604f392320d66556453c9 (diff)
downloadgit-ce74de931d7aea9746e37632534eacc63b0c1a90.zip
git-ce74de931d7aea9746e37632534eacc63b0c1a90.tar.gz
git-ce74de931d7aea9746e37632534eacc63b0c1a90.tar.bz2
ls-files: introduce "--format" option
Add a new option "--format" that outputs index entries informations in a custom format, taking inspiration from the option with the same name in the `git ls-tree` command. "--format" cannot used with "-s", "-o", "-k", "-t", " --resolve-undo","--deduplicate" and "--eol". Signed-off-by: ZheNing Hu <adlternative@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3013-ls-files-format.sh')
-rwxr-xr-xt/t3013-ls-files-format.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/t/t3013-ls-files-format.sh b/t/t3013-ls-files-format.sh
new file mode 100755
index 0000000..efb7450
--- /dev/null
+++ b/t/t3013-ls-files-format.sh
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+test_description='git ls-files --format test'
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+for flag in -s -o -k -t --resolve-undo --deduplicate --eol
+do
+ test_expect_success "usage: --format is incompatible with $flag" '
+ test_expect_code 129 git ls-files --format="%(objectname)" $flag
+ '
+done
+
+test_expect_success 'setup' '
+ printf "LINEONE\nLINETWO\nLINETHREE\n" >o1.txt &&
+ printf "LINEONE\r\nLINETWO\r\nLINETHREE\r\n" >o2.txt &&
+ printf "LINEONE\r\nLINETWO\nLINETHREE\n" >o3.txt &&
+ git add o?.txt &&
+ oid=$(git hash-object o1.txt) &&
+ git update-index --add --cacheinfo 120000 $oid o4.txt &&
+ git update-index --add --cacheinfo 160000 $oid o5.txt &&
+ git update-index --add --cacheinfo 100755 $oid o6.txt &&
+ git commit -m base
+'
+
+test_expect_success 'git ls-files --format objectmode v.s. -s' '
+ git ls-files -s >files &&
+ cut -d" " -f1 files >expect &&
+ git ls-files --format="%(objectmode)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format objectname v.s. -s' '
+ git ls-files -s >files &&
+ cut -d" " -f2 files >expect &&
+ git ls-files --format="%(objectname)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format v.s. --eol' '
+ git ls-files --eol >tmp &&
+ sed -e "s/ / /g" -e "s/ */ /g" tmp >expect 2>err &&
+ test_must_be_empty err &&
+ git ls-files --format="i/%(eolinfo:index) w/%(eolinfo:worktree) attr/%(eolattr) %(path)" >actual 2>err &&
+ test_must_be_empty err &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format path v.s. -s' '
+ git ls-files -s >files &&
+ cut -f2 files >expect &&
+ git ls-files --format="%(path)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format with -m' '
+ echo change >o1.txt &&
+ cat >expect <<-\EOF &&
+ o1.txt
+ o4.txt
+ o5.txt
+ o6.txt
+ EOF
+ git ls-files --format="%(path)" -m >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format with -d' '
+ echo o7 >o7.txt &&
+ git add o7.txt &&
+ rm o7.txt &&
+ cat >expect <<-\EOF &&
+ o4.txt
+ o5.txt
+ o6.txt
+ o7.txt
+ EOF
+ git ls-files --format="%(path)" -d >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format v.s -s' '
+ git ls-files --stage >expect &&
+ git ls-files --format="%(objectmode) %(objectname) %(stage)%x09%(path)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format with --debug' '
+ git ls-files --debug >expect &&
+ git ls-files --format="%(path)" --debug >actual &&
+ test_cmp expect actual
+'
+
+test_done