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

[PATCH 4/5] t2004: demonstrate broken relative path printing

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 24, 2014, 09:43 UTC
Message-ID
<1419414196-58587-5-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1419414196-58587-1-git-send-email-sunshine@sunshineco.com>

checkout-index --temp only properly prints relative paths which are descendants of the current directory. Paths in ancestor or sibling directories (or their children) are often printed in mangled form. For example:

    mkdir a bbb &&
    >file &&
    >bbb/file &&
    git update-index --add file bbb/file &&
    cd a &&
    git checkout-index --temp ../file ../bbb/file
prints:
    .merge_file_ooblek  le
    .merge_file_igloo0  b/file
rather than the correct:
    .merge_file_ooblek  ../file
    .merge_file_igloo0  ../bbb/file

Unfortunately, testing is complicated slightly by relative paths sometimes _appearing_ to be printed correctly, but this is an accident of implementation in which a "correct" copy of the string exists in memory beyond the end of the real string, and that "correct" copy gets printed. This test takes care to avoid the accidentally "correct" behavior by testing with a filename longer than the directory name in which checkout-index is invoked.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/t2004-checkout-cache-temp.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/t/t2004-checkout-cache-temp.sh b/t/t2004-checkout-cache-temp.sh
index 602fbc7..3c2b2b9 100755
--- a/t/t2004-checkout-cache-temp.sh
+++ b/t/t2004-checkout-cache-temp.sh
@@ -206,4 +206,16 @@ test_expect_success 'checkout --temp symlink' '
 	test $(cat $p) = path7
 '
 
+test_expect_failure 'emit well-formed relative path' '
+	rm -f path* .merge_* actual .git/index &&
+	>path0123456789 &&
+	git update-index --add path0123456789 &&
+	(
+		cd asubdir &&
+		git checkout-index --temp -- ../path0123456789 >actual &&
+		test_line_count = 1 actual &&
+		test $(cut "-d	" -f2 actual) = ../path0123456789
+	)
+'
+
 test_done
-- 
2.2.1.267.g0ad48de
Previous: Eric SunshineNext: Eric Sunshine
Message 5 of 8 in “resolve checkout-index --temp path mangling”
  1. 0/5 resolve checkout-index --temp path manglingEric Sunshine, Dec 24, 2014
  2. 1/5 t2004: modernize styleEric Sunshine, Dec 24, 2014
  3. 2/5 t2004: drop unnecessary write-tree/read-treeEric Sunshine, Dec 24, 2014
  4. 3/5 t2004: standardize file naming in symlink testEric Sunshine, Dec 24, 2014
  5. 4/5 t2004: demonstrate broken relative path printingEric Sunshine, Dec 24, 2014
  6. 5/5 checkout-index: fix --temp relative path manglingEric Sunshine, Dec 24, 2014
  7. Eric SunshineDec 28, 2014
  8. Junio C HamanoDec 29, 2014

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.