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

Re: [PATCH 2/2] sh-setup: make require_clean_work_tree() work on orphan branches

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Nov 30, 2015, 12:24 UTC
Message-ID
<20151130132424.Horde.2BMsKJ5eWOY71RtsJbP8UQw@webmail.informatik.kit.edu>
In-Reply-To
<56555A5B.20504@kdbg.org>
Quoting Johannes Sixt <j6t@kdbg.org>:
Show 25 quoted lines
>> --- a/git-sh-setup.sh
>> +++ b/git-sh-setup.sh
>> @@ -200,7 +200,19 @@ require_work_tree () {
>> }
>>
>> require_clean_work_tree () {
>> -	git rev-parse --verify HEAD >/dev/null || exit 1
>> +	if git rev-parse --verify HEAD >/dev/null 2>/dev/null
>> +	then
>> +		compare_to=HEAD
>> +	else
>> +		if [ -z "$ORPHAN_OK" ]
>> +		then
>> +			echo >&2 "Cannot $1: Your current branch does not have any commits yet."
>> +			exit 1
>> +		else
>> +			# SHA1 of an empty tree
>> +			compare_to=4b825dc642cb6eb9a060e54bf8d69288fbee4904
>> +		fi
>> +	fi
>
> It is worrysome that this now throws away any error message of
> rev-parse. A more conservative approach would be to test for -z
> "$ORPHAN_OK" first and entail new behavior only for the "$ORPHAN_OK"
> case.

Those error messages didn't seem to be helpful and in some cases they were even misleading, e.g.:

    $ git checkout --orphan orphan
    $ git rm -rf .
    $ git script valid-branch
    fatal: Needed a single revision
    $ # Huh?  Didn't I just gave you one?!
Gábor
Previous: Johannes SixtNext: Junio C Hamano
Message 7 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.