[coreboot-gerrit] Change in coreboot[master]: util/lint: Unify checks for git worktree

Alex Thiessen (Code Review) gerrit at coreboot.org
Wed Jan 17 00:19:55 CET 2018


Alex Thiessen has uploaded this change for review. ( https://review.coreboot.org/23297


Change subject: util/lint: Unify checks for git worktree
......................................................................

util/lint: Unify checks for git worktree

Linters try to determine whether they are running in a git worktree so
that `git grep` can be used instead of `grep`. These checks are done in
different not truly correct ways and thus the linters don't use `git
grep` when running from a worktree subdirectory, e.g. in a git subtree
environment.

Unify checks using `git rev-parse --is-inside-work-tree`.

Change-Id: I3f54afc99ad0f0e3052cffdd32bdd9649cf3d720
Signed-off-by: Alex Thiessen <alex.thiessen.de+coreboot at gmail.com>
---
M util/lint/lint-008-kconfig
M util/lint/lint-014-qualified-types
M util/lint/lint-016-non-ascii
M util/lint/lint-extended-015-final-newlines
M util/lint/lint-extended-020-signed-off-by
M util/lint/lint-stable-004-style-labels
M util/lint/lint-stable-008-kconfig
M util/lint/lint-stable-013-site-local
M util/lint/lint-stable-017-configs
M util/lint/lint-stable-018-symlinks
M util/lint/lint-stable-019-header-files
M util/lint/lint-stable-021-coreboot-lowercase
12 files changed, 36 insertions(+), 12 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/23297/1

diff --git a/util/lint/lint-008-kconfig b/util/lint/lint-008-kconfig
index d3da17e..8a0042d 100755
--- a/util/lint/lint-008-kconfig
+++ b/util/lint/lint-008-kconfig
@@ -23,7 +23,9 @@
 
 # If coreboot is in a git repo, use git grep to check as it will ignore any
 # files in the tree that aren't checked into git
-if [ -n "$(command -v git)" ] && [ -e ".git" ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	env perl util/lint/kconfig_lint
 else
 	env perl util/lint/kconfig_lint --no_git_grep
diff --git a/util/lint/lint-014-qualified-types b/util/lint/lint-014-qualified-types
index 58b48b7..98679ea 100755
--- a/util/lint/lint-014-qualified-types
+++ b/util/lint/lint-014-qualified-types
@@ -21,7 +21,9 @@
 INCLUDED_FILES='\.[ch]:'
 
 # Use git grep if the code is in a git repo, otherwise use grep.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	GREP_FILES="git grep -n"
 else
 	GREP_FILES="grep -rn"
diff --git a/util/lint/lint-016-non-ascii b/util/lint/lint-016-non-ascii
index 881eeba..beffd83 100755
--- a/util/lint/lint-016-non-ascii
+++ b/util/lint/lint-016-non-ascii
@@ -22,7 +22,9 @@
 EXCLUDED_PHRASES='Copyright\|Ported to\|Intel®\|°C\|°F\|Athlon™\|Copyright.*©\|A-Za-zÀ-ÿ'
 
 # Use git ls-files if the code is in a git repo, otherwise use find.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	FIND_FILES="git ls-files"
 else
 	FIND_FILES="find . "
diff --git a/util/lint/lint-extended-015-final-newlines b/util/lint/lint-extended-015-final-newlines
index bfaa817..1315dbd 100755
--- a/util/lint/lint-extended-015-final-newlines
+++ b/util/lint/lint-extended-015-final-newlines
@@ -20,7 +20,9 @@
 EXCLUDED_FILES='\.jpg$\|\.cksum$\|\.bin$\|\.hex$\|\.ico$\|\.o$\|\.bz2$\|\.xz$\|^.tmpconfig\|\.pyc$\|_shipped$\|sha256$\|\.png$\|\.patch$'
 
 # Use git ls-files if the code is in a git repo, otherwise use find.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	FIND_FILES="git ls-files"
 else
 	FIND_FILES="find . "
diff --git a/util/lint/lint-extended-020-signed-off-by b/util/lint/lint-extended-020-signed-off-by
index 40b6e9e..065b286 100755
--- a/util/lint/lint-extended-020-signed-off-by
+++ b/util/lint/lint-extended-020-signed-off-by
@@ -16,7 +16,9 @@
 # DESCR: Check for a signed-off-by line on the latest git commit
 
 # This test is mainly for the jenkins server
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	if [ -z "$(git log -n 1 | grep '[[:space:]]\+Signed-off-by: ')" ]; then
 		echo "No Signed-off-by line in commit message"
 	fi
diff --git a/util/lint/lint-stable-004-style-labels b/util/lint/lint-stable-004-style-labels
index 7b68b4a..698b22d 100755
--- a/util/lint/lint-stable-004-style-labels
+++ b/util/lint/lint-stable-004-style-labels
@@ -18,7 +18,9 @@
 LC_ALL=C export LC_ALL
 
 # Use git ls-files if the code is in a git repo, otherwise use find.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	FIND_FILES="git ls-files"
 else
 	FIND_FILES="find src"
diff --git a/util/lint/lint-stable-008-kconfig b/util/lint/lint-stable-008-kconfig
index 06e41b8..25d04b6 100755
--- a/util/lint/lint-stable-008-kconfig
+++ b/util/lint/lint-stable-008-kconfig
@@ -23,7 +23,9 @@
 
 # If coreboot is in a git repo, use git grep to check as it will ignore any
 # files in the tree that aren't checked into git
-if [ -n "$(command -v git)" ] && [ -e ".git" ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	env perl util/lint/kconfig_lint --warnings_off 2>&1
 else
 	env perl util/lint/kconfig_lint --no_git_grep --warnings_off 2>&1
diff --git a/util/lint/lint-stable-013-site-local b/util/lint/lint-stable-013-site-local
index 43c4542..d701ee0 100755
--- a/util/lint/lint-stable-013-site-local
+++ b/util/lint/lint-stable-013-site-local
@@ -22,7 +22,9 @@
 
 LC_ALL=C export LC_ALL
 
-if [ -n "$(command -v git)" ]  && [ -e ".git" ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	if [ -n "$(git ls-files site-local/*)" ]; then
 		echo "Error: site-local must be kept separate from the coreboot repository."
 	fi
diff --git a/util/lint/lint-stable-017-configs b/util/lint/lint-stable-017-configs
index 782c183..6d7393d 100755
--- a/util/lint/lint-stable-017-configs
+++ b/util/lint/lint-stable-017-configs
@@ -19,7 +19,9 @@
 SYMBOLS='CONFIG_ARCH_\|CONFIG_MAINBOARD_HAS_'
 
 # Use git grep if the code is in a git repo, otherwise use grep.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	GREP="git grep -l"
 else
 	GREP="grep -rl"
diff --git a/util/lint/lint-stable-018-symlinks b/util/lint/lint-stable-018-symlinks
index 7865f55..4a67bac 100755
--- a/util/lint/lint-stable-018-symlinks
+++ b/util/lint/lint-stable-018-symlinks
@@ -19,7 +19,9 @@
 EXCLUDED_DIRS='^3rdparty\|^site-local'
 
 # If the code is in a git repo, only print files that are checked in
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	git ls-tree -r HEAD | \
 		grep ^120000 | \
 		cut -f2 | \
diff --git a/util/lint/lint-stable-019-header-files b/util/lint/lint-stable-019-header-files
index e98c3b5..56e2ca8 100755
--- a/util/lint/lint-stable-019-header-files
+++ b/util/lint/lint-stable-019-header-files
@@ -23,7 +23,9 @@
 HEADER_FILES="k*config"
 
 # Use git grep if the code is in a git repo, otherwise use grep.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	GREP_FILES="git grep -n"
 else
 	GREP_FILES="grep -rn"
diff --git a/util/lint/lint-stable-021-coreboot-lowercase b/util/lint/lint-stable-021-coreboot-lowercase
index 82e2dd4..a71d204 100755
--- a/util/lint/lint-stable-021-coreboot-lowercase
+++ b/util/lint/lint-stable-021-coreboot-lowercase
@@ -19,7 +19,9 @@
 EXCLUDE='^3rdparty/\|util/crossgcc/xgcc\|Binary file\|coreboot\|COREBOOT\|CorebootPayload\|CorebootModule\|minnowboard.org/Coreboot\|.*\.patch$\|CorebootBdsLib\|^payloads/external'
 
 # Use git grep if the code is in a git repo, otherwise use grep.
-if [ -n "$(command -v git)" ] && [ -d .git ]; then
+if [ -n "$(command -v git)" ] && \
+	[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]
+then
 	GREP_FILES="git grep -in"
 
 	# Check last commit message

-- 
To view, visit https://review.coreboot.org/23297
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3f54afc99ad0f0e3052cffdd32bdd9649cf3d720
Gerrit-Change-Number: 23297
Gerrit-PatchSet: 1
Gerrit-Owner: Alex Thiessen <alex.thiessen.de+coreboot at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180116/5cdaa569/attachment.html>


More information about the coreboot-gerrit mailing list