RemoteContainsCommit cannot verify detached HEAD commits via git ls-remote #35
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
heiko/gogogo#35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
RemoteContainsCommitusesgit ls-remoteto check whether the current HEAD commit exists on the remote.git ls-remoteonly lists ref tips (branch heads and tags) — it cannot confirm that an arbitrary commit SHA is reachable from any remote ref.This means the check silently passes (returns
true) for detached HEAD commits that are not the tip of any remote branch or tag. This is the correct pragmatic behaviour for CI pipelines (where detached HEAD almost always means the commit came from the remote), but it means the safety net is absent for that case.Affected scenario
If HEAD is at D and D is not a remote branch/tag tip,
RemoteContainsCommitreturnstruewithout actually verifying D exists on the remote.Prior approach
The original
git branch -r --contains <SHA>would have caught ancestors of remote branches, but it fails entirely in shallow clones (no local remote-tracking refs), which is the common CI case.Possible fix
For the detached HEAD + no matching ref case, attempt
git fetch --depth=1 <remote> <sha>as a last resort. If the server supportsuploadpack.allowReachableSHA1InWant(enabled by default on Forgejo/Gitea), this would confirm the commit is reachable. If it fails, reject.This needs to be weighed against the side effects of a fetch operation and the assumption about server configuration.