Re: [PATCH] scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks

Andreas Schwab
2018-11-10T10:42:21Z

On Nov 10 2018, Genki Sky <sky@genki.is> wrote:

> On Fri, 9 Nov 2018 10:34:37 -0800, Brian Norris <briannorris@chromium.org> wrote:
>> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
>> index 71f39410691b..eab1f90de50d 100755
>> --- a/scripts/setlocalversion
>> +++ b/scripts/setlocalversion
>> @@ -73,8 +73,19 @@ scm_version()
>> printf -- '-svn%s' "`git svn find-rev $head`"
>> fi
>>
>> - # Check for uncommitted changes
>> - if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
>> + # Check for uncommitted changes.
>> + # First, with git-status, but --no-optional-locks is only
>> + # supported in git >= 2.14, so fall back to git-diff-index if
>> + # it fails. Note that git-diff-index does not refresh the
>> + # index, so it may give misleading results. See
>> + # git-update-index(1), git-diff-index(1), and git-status(1).
>> + local git_status
>> + git_status="$(git --no-optional-locks status -uno --porcelain 2>/dev/null)"
>> + if [ $? -eq 0 ]; then
>> + if echo "$git_status" | grep -qv '^.. scripts/package'; then
>
> Shouldn't this be:
>
> if printf '%s' "$git_status" | grep -qv '^.. scripts/package'; then
>
> I.e., use printf not echo? Because of echo introducing a newline.

The input to grep should be a text file, thus should end with a newline.

Andreas.

--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."