Skip to content

Commit ff64dd4

Browse files
computersforpeacemasahir0y
authored andcommitted
scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks
git-diff-index does not refresh the index for you, so using it for a "-dirty" check can give misleading results. Commit 6147b1c ("scripts/setlocalversion: git: Make -dirty check more robust") tried to fix this by switching to git-status, but it overlooked the fact that git-status also writes to the .git directory of the source tree, which is definitely not kosher for an out-of-tree (O=) build. That is getting reverted. Fortunately, git-status now supports avoiding writing to the index via the --no-optional-locks flag, as of git 2.14. It still calculates an up-to-date index, but it avoids writing it out to the .git directory. So, let's retry the solution from commit 6147b1c using this new flag first, and if it fails, we assume this is an older version of git and just use the old git-diff-index method. It's hairy to get the 'grep -vq' (inverted matching) correct by stashing the output of git-status (you have to be careful about the difference betwen "empty stdin" and "blank line on stdin"), so just pipe the output directly to grep and use a regex that's good enough for both the git-status and git-diff-index version. Cc: Christian Kujau <[email protected]> Cc: Guenter Roeck <[email protected]> Suggested-by: Alexander Kapshuk <[email protected]> Signed-off-by: Brian Norris <[email protected]> Tested-by: Genki Sky <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 5818c68 commit ff64dd4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/setlocalversion

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,16 @@ scm_version()
7373
printf -- '-svn%s' "`git svn find-rev $head`"
7474
fi
7575

76-
# Check for uncommitted changes
77-
if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
76+
# Check for uncommitted changes.
77+
# First, with git-status, but --no-optional-locks is only
78+
# supported in git >= 2.14, so fall back to git-diff-index if
79+
# it fails. Note that git-diff-index does not refresh the
80+
# index, so it may give misleading results. See
81+
# git-update-index(1), git-diff-index(1), and git-status(1).
82+
if {
83+
git --no-optional-locks status -uno --porcelain 2>/dev/null ||
84+
git diff-index --name-only HEAD
85+
} | grep -qvE '^(.. )?scripts/package'; then
7886
printf '%s' -dirty
7987
fi
8088

0 commit comments

Comments
 (0)