All of lore.kernel.org
 help / color / mirror / Atom feed
From: Genki Sky <sky@genki.is>
To: linux-kbuild@vger.kernel.org
Cc: Christian Kujau <lists@nerdbynature.de>,
	Elazar Leibovich <elazar.leibovich@oracle.com>,
	Junio C Hamano <gitster@pobox.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Michal Marek <michal.lkml@markovi.net>,
	Nico Schottelius <nico-linuxsetlocalversion@schottelius.org>
Subject: [PATCH] scripts/setlocalversion: git: Make -dirty check more robust
Date: Tue, 28 Aug 2018 23:26:24 -0400	[thread overview]
Message-ID: <de6839047158272d1976ab023b9a222c09679846.1535512872.git.sky@genki.is> (raw)

$(git diff-index) relies on the index being refreshed. This refreshing
of the index used to happen, but was removed in cdf2bc632ebc
("scripts/setlocalversion on write-protected source tree", 2013-06-14)
due to issues with a read-only filesystem.

If the index is not refreshed, one runs into problems. E.g. as
described in [0], git stores the uid in its index, so even if just the
uid has changed (or git is tricked into thinking so), then we will
think the tree is dirty. So as in [1], if you package linux-git with a
system that uses fakeroot(1), you get a "-dirty" version. Unless you
manually $(git update-index --refresh) themselves.

The simplest solution seems to be $(git status --porcelain), with an
additional flag saying "ignore untracked files". It seems clearer
about what it does, and avoids issues regarding cached indexes and
writable filesystems, but still has stable output for scripting.

[0]: https://public-inbox.org/git/0190ae30-b6c8-2a8b-b1fb-fd9d84e6dfdf@oracle.com/
[1]: https://bbs.archlinux.org/viewtopic.php?id=236702

Signed-off-by: Genki Sky <sky@genki.is>
---

Notes:

   Testing: I ran $(git status -uno .... && echo dirty) after each of
   the following commands, checking sanity:

     % > Makefile
     % git checkout Makefile
     % chmod -w .git
     % > scripts/package/Makefile
     % chmod +w .git
     % git checkout scripts/package/Makefile
     % touch new_file
     % touch scripts/package/new_file
     % rm new_file scripts/package/new_file
     % mv Makefile .clang-format
     % git checkout Makefile .clang-format

 scripts/setlocalversion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 71f39410691b..79f7dd57d571 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -74,7 +74,7 @@ scm_version()
 		fi

 		# Check for uncommitted changes
-		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+		if git status -uno --porcelain | grep -qv '^.. scripts/package'; then
 			printf '%s' -dirty
 		fi

--
2.18.0

             reply	other threads:[~2018-08-29  7:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29  3:26 Genki Sky [this message]
2018-08-31 16:21 ` [PATCH] scripts/setlocalversion: git: Make -dirty check more robust Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=de6839047158272d1976ab023b9a222c09679846.1535512872.git.sky@genki.is \
    --to=sky@genki.is \
    --cc=elazar.leibovich@oracle.com \
    --cc=gitster@pobox.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    --cc=michal.lkml@markovi.net \
    --cc=nico-linuxsetlocalversion@schottelius.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.