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

[PATCH] t7300: repair filesystem permissions with test_when_finished

From
Jeff King <peff@peff.net>
Date
Jul 2, 2014, 18:44 UTC
Message-ID
<20140702184429.GA32538@sigill.intra.peff.net>

We create a directory that cannot be removed, confirm that it cannot be removed, and then fix it like:

  chmod 0 foo &&
  test_must_fail git clean -d -f &&
  chmod 755 foo

If the middle step fails but leaves the directory (e.g., the bug is that clean does not notice the failure), this pollutes the test repo with an unremovable directory. Not only does this cause further tests to fail, but it means that "rm -rf" fails on the whole trash directory, and the user has to intervene manually to even re-run the test script.

We can bump the "chmod 755" recovery to a test_when_finished block to be sure that it always runs.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t7300-clean.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 74de814..04118ad 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -426,10 +426,10 @@ test_expect_success SANITY 'removal failure' '
 
 	mkdir foo &&
 	touch foo/bar &&
+	test_when_finished "chmod 755 foo" &&
 	(exec <foo/bar &&
 	 chmod 0 foo &&
-	 test_must_fail git clean -f -d &&
-	 chmod 755 foo)
+	 test_must_fail git clean -f -d)
 '
 
 test_expect_success 'nested git work tree' '
-- 
2.0.0.566.gfe3e6b2
Next: Jonathan Nieder
Message 1 of 8 in “t7300: repair filesystem permissions with test_when_finished”
  1. t7300: repair filesystem permissions with test_when_finishedJeff King, Jul 2, 2014
  2. Jonathan NiederJul 2, 2014
  3. Jeff KingJul 2, 2014
  4. Junio C HamanoJul 2, 2014
  5. Junio C HamanoJul 2, 2014
  6. [RFH] "git clean" deletes excluded files in untracked directoriesJeff King, Jul 2, 2014
  7. Junio C HamanoJul 22, 2014
  8. Junio C HamanoJul 22, 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.