From: SZEDER Gábor Date: Mon, 30 Nov 2015 12:24:24 GMT Subject: Re: [PATCH 2/2] sh-setup: make require_clean_work_tree() work on orphan branches Message-ID: <20151130132424.Horde.2BMsKJ5eWOY71RtsJbP8UQw@webmail.informatik.kit.edu> In-Reply-To: <56555A5B.20504@kdbg.org> Quoting Johannes Sixt : >> --- 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