git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] t7001: use "ls-files --format" instead of "cut"

From
Jeff King <peff@peff.net>
Date
May 8, 2023, 19:01 UTC
Message-ID
<20230508190146.GB2366490@coredump.intra.peff.net>
In-Reply-To
<20230508185953.GA2108869@coredump.intra.peff.net>

Since ls-files recently learned a "--format" option, we can use that rather than asking for all of "--stage" and then pulling out the bits we want with "cut". That's simpler and avoids two extra processes (one for cut, and one for the subshell to hold the intermediate result).

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t7001-mv.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index ea70419928..2e6a3c0a54 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -5,8 +5,7 @@ test_description='git mv in subdirs'
 . "$TEST_DIRECTORY"/lib-diff-data.sh
 
 index_at_path () {
-	entry=$(git ls-files --stage "$@") &&
-	echo "$entry" | cut -f 1
+	git ls-files --format='%(objectmode) %(objectname) %(stage)' "$@"
 }
 
 test_expect_success 'mv -f refreshes updated index entry' '
-- 
2.40.1.802.gdef2a8734a
Previous: Jeff KingNext: Jeff King
Message 3 of 6 in “dropping "verbose" test helper function”
  1. 0/3 dropping "verbose" test helper functionJeff King, May 8, 2023
  2. 1/3 t7001: avoid git on upstream of pipeJeff King, May 8, 2023
  3. 2/3 t7001: use "ls-files --format" instead of "cut"Jeff King, May 8, 2023
  4. 3/3 t: drop "verbose" helper functionJeff King, May 8, 2023
  5. Taylor BlauMay 8, 2023
  6. Taylor BlauMay 8, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.