From patchwork Thu Dec 29 07:43:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13083331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDA21C4332F for ; Thu, 29 Dec 2022 07:43:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbiL2Hn2 (ORCPT ); Thu, 29 Dec 2022 02:43:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbiL2Hn1 (ORCPT ); Thu, 29 Dec 2022 02:43:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB6A1B486; Wed, 28 Dec 2022 23:43:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 483B161724; Thu, 29 Dec 2022 07:43:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DDAEC433EF; Thu, 29 Dec 2022 07:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672299805; bh=ha9gPkeEMdP/2N37rSOoAud9ZwoPXuJqw+mMc7OloXw=; h=From:To:Cc:Subject:Date:From; b=eY45LjFSbjq9lFd3TuaYsVftNInFTpCnJSUPIc9G3xcl3YXH1kcMdNAtysho+QDM/ H/fpb4/tN4jSQgqtT2H3h0HkALhoj1kT/ZV11iYMJRzmaGQHWLNCuP4Ly4bmD7iMyN xLgz1XJKJKdlIM29yJxHAvHn/uUYZziAegkLUP5fSZOuLWRGVp3EZCOYp4yauWVFzO CEbZQ3z2UJ+2KI/wPwyLGc+Xd41xDd7NNvBZEs1o1c6DDlnCY5E2/EFaq9tXoFuLJ4 AOYGZtzCjoZJ/hoVoM8U6+Rai/QFWl4eLe0aBB3o8Ly+SNbt+IknbepTOkPd0wJRoL nBwY4ZOamaLfg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Miguel Ojeda , Alex Gaynor , Andrew Davis , Kees Cook , Wedson Almeida Filho Subject: [PATCH v3 1/2] .gitignore: update the command to check tracked files being ignored Date: Thu, 29 Dec 2022 16:43:09 +0900 Message-Id: <20221229074310.906556-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Recent git versions do not accept the noted command. $ git ls-files -i --exclude-standard fatal: ls-files -i must be used with either -o or -c The -c was implied before, but we need to make it explicit since git commit b338e9f66873 ("ls-files: error out on -i unless -o or -c are specified"). Also, replace --exclude-standard with --exclude-per-directory=.gitignore so that everyone will get consistent results. git-ls-files(1) says: --exclude-standard Add the standard Git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file. We cannot predict what is locally added to .git/info/exclude or the user's global exclusion file. We can only manage .gitignore files committed to the repository. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda --- Changes in v3: - Fix a typo. Update commit description per Miguel .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3ec73ead6757..2e2e3d1eeaee 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ # subdirectories here. Add them in the ".gitignore" file # in that subdirectory instead. # -# NOTE! Please use 'git ls-files -i --exclude-standard' +# NOTE! Please use 'git ls-files -i -c --exclude-per-directory=.gitignore' # command after changing this file, to see if there are # any tracked files which get ignored after the change. # From patchwork Thu Dec 29 07:43:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13083332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFFB9C3DA7D for ; Thu, 29 Dec 2022 07:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbiL2Hn7 (ORCPT ); Thu, 29 Dec 2022 02:43:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232996AbiL2Hnc (ORCPT ); Thu, 29 Dec 2022 02:43:32 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D89FD3; Wed, 28 Dec 2022 23:43:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E65386170C; Thu, 29 Dec 2022 07:43:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E3E0C433D2; Thu, 29 Dec 2022 07:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672299810; bh=/mTmrBpGVR4tHpil4FIqdwtv6srLo9Xnga3QkS7c6QQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FlqslimJZoIeBn+FrqTdBOBuFMPmaZN6s2NfM7h++iksFK0Zp4luuvQTCKa6Zwosm ShF07zAQsN11sK8jNuRVcc7h73IWcywsc3r0QfCpQmqoXyNQuz9ilOMyZGozbcPJkY 3XGLTedCy75KtsFWb1/GOLhjRLPR1OlmoHNy0FInREsa9z6RBDn9roy3lSCtl8NnZs 63M28ALmLFceylC+ruLSsaWEwAjZMLUnA14zDMIMjHrcthe4z+FvLOz/UKrSmhn29s hUoiHRZHZSIudNBpW4zDT9eFyU0LPMvuRpRAjS8Aba92jtdlbDU0T+lomB0OrpxGcm D2GkXunoyzudg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Nick Desaulniers Subject: [PATCH v3 2/2] kbuild: make W=1 warn files that are tracked but ignored by git Date: Thu, 29 Dec 2022 16:43:10 +0900 Message-Id: <20221229074310.906556-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221229074310.906556-1-masahiroy@kernel.org> References: <20221229074310.906556-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org The top .gitignore comments about how to detect files breaking .gitignore rules, but people rarely care about it. Add a new W=1 warning to detect files that are tracked but ignored by git. If git is not installed or the source tree is not tracked by git at all, this script does not print anything. Running it on v6.2-rc1 detected the following: $ make W=1 misc-check Documentation/devicetree/bindings/.yamllint: warning: ignored by one of the .gitignore files drivers/clk/.kunitconfig: warning: ignored by one of the .gitignore files drivers/gpu/drm/tests/.kunitconfig: warning: ignored by one of the .gitignore files drivers/hid/.kunitconfig: warning: ignored by one of the .gitignore files fs/ext4/.kunitconfig: warning: ignored by one of the .gitignore files fs/fat/.kunitconfig: warning: ignored by one of the .gitignore files kernel/kcsan/.kunitconfig: warning: ignored by one of the .gitignore files lib/kunit/.kunitconfig: warning: ignored by one of the .gitignore files mm/kfence/.kunitconfig: warning: ignored by one of the .gitignore files tools/testing/selftests/arm64/tags/.gitignore: warning: ignored by one of the .gitignore files tools/testing/selftests/arm64/tags/Makefile: warning: ignored by one of the .gitignore files tools/testing/selftests/arm64/tags/run_tags_test.sh: warning: ignored by one of the .gitignore files tools/testing/selftests/arm64/tags/tags_test.c: warning: ignored by one of the .gitignore files These are ignored by the '.*' or 'tags' in the top .gitignore, but there is no rule to negate it. You might be tempted to do 'git add -f' but I want to have the real issue fixed (by fixing a .gitignore, or by renaming files, etc.). Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor Reviewed-by: Nicolas Schier Tested-by: Nicolas Schier --- Changes in v3: - change working directory to srctree (Nicolas) Changes in v2: - Add $(srctree)/ to make it work with O= Makefile | 6 ++++++ scripts/misc-check | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 scripts/misc-check diff --git a/Makefile b/Makefile index acce5ec514f6..c0d7c75d8f14 100644 --- a/Makefile +++ b/Makefile @@ -1848,6 +1848,12 @@ rust-analyzer: # Misc # --------------------------------------------------------------------------- +PHONY += misc-check +misc-check: + $(Q)$(srctree)/scripts/misc-check + +all: misc-check + PHONY += scripts_gdb scripts_gdb: prepare0 $(Q)$(MAKE) $(build)=scripts/gdb diff --git a/scripts/misc-check b/scripts/misc-check new file mode 100755 index 000000000000..d40d5484e0c5 --- /dev/null +++ b/scripts/misc-check @@ -0,0 +1,19 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only + +set -e + +# Detect files that are tracked but ignored by git. This is checked only when +# ${KBUILD_EXTRA_WARN} contains 1, git is installed, and the source tree is +# tracked by git. +check_tracked_ignored_files () { + case "${KBUILD_EXTRA_WARN}" in + *1*) ;; + *) return;; + esac + + git -C ${srctree:-.} ls-files -i -c --exclude-per-directory=.gitignore 2>/dev/null | + sed 's/$/: warning: ignored by one of the .gitignore files/' >&2 +} + +check_tracked_ignored_files