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

Re: [PATCH 1/2] Add tests for git-sh-setup's require_clean_work_tree()

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 21, 2016, 04:52 UTC
Message-ID
<xmqqa8nzzg7z.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160121022711.Horde.7Nh0N0fTAbd0JWIA99KKFQF@webmail.informatik.kit.edu>
SZEDER Gábor <szeder@ira.uka.de> writes:
Show 34 quoted lines
> Quoting Junio C Hamano <gitster@pobox.com>:
>
>>> +test_expect_success 'error on clean index and worktree while on  
>>> orphan branch' '
>>> +	test_when_finished "git checkout master" &&
>>> +	git checkout --orphan orphan &&
>>> +	git reset --hard &&
>>> +	test_must_fail run_require_clean_work_tree
>>> +'
>>
>> The title is wrong.  Immediately after creating and getting on an
>> orphan branch, you have stuff in the index that is not committed to
>> the branch, so your index cannot be clean by definition.
>
> The index contains the file 'file', so it's not clean indeed.
>
>> The
>> contents of the working tree may or may not be clean immediately
>> after getting on a new orphan branch, but you are doing "reset
>> --hard" to make the index and the working tree agree,
>
> ... and match HEAD, which in this case means both the index and the
> worktree become empty.
>
> 'git rm -r .' would have made the intent clearer.  Or 'git init emptyrepo'.
>
>> so this is
>> testing the "clean working tree" case, I think.
>
> So the question is, before we go any further: are an empty index and
> empty worktree clean when HEAD doesn't point to a commit?  (either after
> the command sequence in the above test, or right after 'git init').
>
> I do think they are clean.
That is "rm -fr test && git init test && cd test" case, right?

It may be consistent to define it as clean, but I am not sure existing operations that require a clean working tree is useful in such a state (filter-branch, pull-rebase and rebase are the big users, and none of them is so useful with an unborn history), so loosening the definition would be not just helpful for them but would be harmful, as they (implicitly) rely on require-clean to stop the command early before they try to do something that needs an existing history.

So, I am not sure if it is a good idea.
Previous: SZEDER Gábor
Message 11 of 11 in “Add tests for git-sh-setup's require_clean_work_tree()”
  1. 1/2 Add tests for git-sh-setup's require_clean_work_tree()SZEDER Gábor, Nov 24, 2015
  2. 2/2 sh-setup: make require_clean_work_tree() work on orphan branchesSZEDER Gábor, Nov 24, 2015
  3. Jeff KingNov 24, 2015
  4. SZEDER GáborNov 30, 2015
  5. Junio C HamanoDec 2, 2015
  6. Johannes SixtNov 25, 2015
  7. SZEDER GáborNov 30, 2015
  8. Junio C HamanoJan 21, 2016
  9. Junio C HamanoJan 20, 2016
  10. SZEDER GáborJan 21, 2016
  11. Junio C HamanoJan 21, 2016

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.