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

Re: [PATCH] describe: refresh the index when 'broken' flag is used

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 24, 2024, 16:34 UTC
Message-ID
<xmqqcyo6cnbb.fsf@gitster.g>
In-Reply-To
<735b4a95-fe8e-4bff-9dd3-10ddd4bdb5b5@gmail.com>
Abhijeet Sonar <abhijeet.nkt@gmail.com> writes:
Show 5 quoted lines
> I would like to change the owner of a file
> in the test case I am writing -- an operation
> that requires super-user privileges.  I am not
> sure if it is okay to do that in tests.  Since
> that would require running tests with `sudo`.

What is the reason why you want to change the owner of a file in your test?

If it is merely to make sure you cannot write to the .git/index file, temporarily doing chmod of the .git directory in a test (with POSIXPERM prerequisite) may be one way to do so, and you do not need the second user in the system test is running.

Or if you pretend that you have a second process that is holding the lock in .git/index by creating .git/index.lock file yourself, that would also prevent your tested command from touching the index.

The latter approach would result in a test that may look like so (I am writing this in my mail client, and I expect there may be some fix ups needed):

test_expect_success 'see what --broken does upon unwritable index' '
        test_when_finished "rm -f .git/index.lock" &&
        test_commit A A.file &&
        echo changed >>A.file &&
        >.git/index.lock &&
	test_must_fail git describe --dirty >actual 2>error &&
	test_grep "could not write index" error &&
	git describe --broken --dirty >actual 2>error &&
	test_grep ! "could not write index" error &&
	echo ...expected.describe.result... >expect &&
	test_cmp expect actual
'
HTH.
Previous: Abhijeet SonarNext: Abhijeet Sonar
Message 7 of 14 in “describe: refresh the index when 'broken' flag is used”
  1. describe: refresh the index when 'broken' flag is usedAbhijeet Sonar, Jun 23, 2024
  2. Abhijeet SonarJun 23, 2024
  3. Karthik NayakJun 24, 2024
  4. Phillip WoodJun 24, 2024
  5. Abhijeet SonarJun 24, 2024
  6. Abhijeet SonarJun 24, 2024
  7. Junio C HamanoJun 24, 2024
  8. Abhijeet SonarJun 24, 2024
  9. Junio C HamanoJun 24, 2024
  10. Abhijeet SonarJun 25, 2024
  11. describe: refresh the index when 'broken' flag is usedAbhijeet Sonar, Jun 25, 2024
  12. Karthik NayakJun 25, 2024
  13. Abhijeet SonarJun 25, 2024
  14. Karthik NayakJun 25, 2024

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.