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

Re: [PATCH] multi-pack-index: fix --object-dir from outside repo

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 23, 2021, 16:06 UTC
Message-ID
<xmqq1r6krvrp.fsf@gitster.g>
In-Reply-To
<caafaf945ec43ba606b054bf4c4faa42e35a8db1.camel@sipsolutions.net>
Johannes Berg <johannes@sipsolutions.net> writes:
> Makes sense. FWIW, the test *did* restore the CWD so things worked, and
> subshells are actually ugly (need to import test-lib-functions.sh again
> if you want to use those), but I'll make it work somehow.

You do not need to dot-include test-lib-functions or anything ugly or special. The variables (not only the exported ones but regular shell variables) and shell functions that is visible immediately before you enter the opening "(" are all visible in the subshell.

The only notable difference you need to keep in mind when using subshell is that you cannot affect variables and environment in general of the calling shell. In this case, you are taking advantage of it---no matter where you chdir to, the main test procedure that spawned the subshell will not be affected even if your tests fail inside a subshell. But it also disallows you from doing certain things that rely on the ability to modify shell variables, like setting up test_when_finished clean-up routine.

> More importantly, how do you feel about the "cd /"?

Please don't. If somebody had a repository in /.git and the program you are testing is buggy, you'd risk destroying it. In general, it is not a good idea to step outside the test directory you are given, especially if you are *not* limiting yourself to read-only operation.

> The tests are always run in a place where there's a parent git folder
> (even if it's git itself), so you cannot reproduce the segfault in a
> test without the "cd /"

There is a "nongit" test helper in the test suite. Would that work for your case?

Thanks.
Previous: Junio C HamanoNext: Taylor Blau
Message 9 of 11 in “multi-pack-index: fix --object-dir from outside repo”
  1. multi-pack-index: fix --object-dir from outside repoJohannes Berg, Aug 20, 2021
  2. Derrick StoleeAug 22, 2021
  3. Johannes BergAug 23, 2021
  4. Junio C HamanoAug 23, 2021
  5. Johannes BergAug 23, 2021
  6. Derrick StoleeAug 23, 2021
  7. Johannes BergAug 23, 2021
  8. Junio C HamanoAug 23, 2021
  9. Junio C HamanoAug 23, 2021
  10. Taylor BlauAug 23, 2021
  11. Johannes BergAug 23, 2021

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.