util/gitutil: Full/ShortCommit(): replace git show with git rev-parse#3747
Open
jegorbunov wants to merge 1 commit intodocker:masterfrom
Open
util/gitutil: Full/ShortCommit(): replace git show with git rev-parse#3747jegorbunov wants to merge 1 commit intodocker:masterfrom
jegorbunov wants to merge 1 commit intodocker:masterfrom
Conversation
200f023 to
ba6eae3
Compare
2f19caf to
758cdba
Compare
758cdba to
28c48d8
Compare
thaJeztah
reviewed
Apr 7, 2026
Comment on lines
61
to
62
Member
There was a problem hiding this comment.
Looks like your PR was opened from an outdated branch and pulled in a commit from #3750 - can you try rebasing?
28c48d8 to
93b562c
Compare
The FullCommit and ShortCommit methods are expected to simply get the
hash of HEAD. Using `git show` for this purpose is overkill because
`git show` can have side effects that are annoying when `docker build`
runs in a CI environment:
1) CI environments (e.g. CircleCI) may use blobless clones, where the
target repository is checked out using `git clone --filter=blob:none {url}`.
2) `git show` does more than just discover the hash of a specified revision:
in general, it needs parent commits and blobs to compute the diff. When
a blobless clone is used, `git show` may try to download these additional
blobs from the remote. From my experiments, this happens even when
`--quiet` or `--no-patch` is specified.
3) If the `docker build` step runs in an environment where Git is not configured
properly to download from the remote, the step may hang indefinitely, as it did
in my case with the following prompt:
The authenticity of host 'github.com (140.82.112.3)' can't be established.
ED25519 key fingerprint is SHA256:+....
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Notes on test fixes:
git rev-parse HEAD doesn't need any `--`, however, when it is called
on an empty repo git returns an error:
```
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
```
So, it is both IsUnknownRevision and IsAmbiguousArgument.
Lets simply fix the test by flipping the check: I don't see
any dependency on this behavior in non-test code.
Moreover, `git rev-parse --short HEAD` fails with another error:
```
fatal: Needed a single revision
```
Lets handle it as IsUnknownRevision
Signed-off-by: Jegor Gorbunov <jegor.gorbunov@point-devel.com>
93b562c to
9b56d03
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The FullCommit and ShortCommit methods are expected to simply get the hash of HEAD. Using
git showfor this purpose is overkill becausegit showcan have side effects that are annoying whendocker buildruns in a CI environment:CI environments (e.g. CircleCI) may use blobless clones, where the target repository is checked out using
git clone --filter=blob:none {url}.git showdoes more than just discover the hash of a specified revision: in general, it needs parent commits and blobs to compute the diff. When a blobless clone is used,git showmay try to download these additional blobs from the remote. From my experiments, this happens even when--quietor--no-patchis specified.If the
docker buildstep runs in an environment where Git is not configured properly to download from the remote, the step may hang indefinitely, as it did in my case with the following prompt:The authenticity of host 'github.com (140.82.112.3)' can't be established. ED25519 key fingerprint is SHA256:+.... This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])?