From: Hamdy Abou El Anein <info@daylightlinux.ch>
To: sashal@kernel.org
Cc: hamdy.aea@protonmail.com, linux-kernel@vger.kernel.org
Subject: [PATCH v2] scripts: git-resolve: ignore non-commit objects
Date: Wed, 4 Nov 2026 06:43:32 +0100 [thread overview]
Message-ID: <20261104054332.10869-1-info@daylightlinux.ch> (raw)
In-Reply-To: <20261103164202.129624-1-info@daylightlinux.ch>
From: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
git rev-parse --disambiguate lists objects of every type. A unique blob
or tree prefix is therefore returned successfully as a commit ID. Such
an ID cannot be used as a commit reference or Fixes tag.
Filter the candidates by object type before deciding whether the prefix
is unique or looking up its subject.
Tested in a temporary Git repository: a real commit prefix resolves to
its full ID, while blob and tree prefixes produce the command-line
error.
AI assistance: ChatGPT/Codex identified the issue and prepared the
change, commit message and executable regression tests.
Fixes: 7ae52a3d7f51 ("scripts: Add git-resolve tool for full SHA-1 resolution")
Signed-off-by: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
---
scripts/git-resolve.sh | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/scripts/git-resolve.sh b/scripts/git-resolve.sh
index e9b5940c0f28..7d14cf279e86 100755
--- a/scripts/git-resolve.sh
+++ b/scripts/git-resolve.sh
@@ -49,7 +49,9 @@ git_resolve_commit() {
# Get all possible matching commit IDs
local matches
- readarray -t matches < <(git rev-parse --disambiguate="$commit_id" 2>/dev/null)
+ readarray -t matches < <(git rev-parse --disambiguate="$commit_id" 2>/dev/null |
+ git cat-file --batch-check='%(objectname) %(objecttype)' |
+ awk '$2 == "commit" { print $1 }')
# Return immediately if we have exactly one match
if [ ${#matches[@]} -eq 1 ]; then
@@ -191,7 +193,9 @@ fi
# Skip validation in force mode
if [ -z "$force" ]; then
# Validate that the first argument matches at least one git commit
- if [ "$(git rev-parse --disambiguate="$1" 2>/dev/null | wc -l)" -eq 0 ]; then
+ if [ "$(git rev-parse --disambiguate="$1" 2>/dev/null |
+ git cat-file --batch-check='%(objectname) %(objecttype)' |
+ awk '$2 == "commit" { count++ } END { print count + 0 }')" -eq 0 ]; then
echo "Error: '$1' does not match any git commit"
exit 1
fi
--
2.56.0
prev parent reply other threads:[~2026-11-04 5:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 16:42 [PATCH] " Hamdy Abou El Anein
2026-11-03 17:26 ` Sasha Levin
2026-11-04 5:43 ` Hamdy Abou El Anein [this message]
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=20261104054332.10869-1-info@daylightlinux.ch \
--to=info@daylightlinux.ch \
--cc=hamdy.aea@protonmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sashal@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®