Harden git-sync abbreviated commit verification#338
Conversation
|
Code review posted below - please see the review details. |
Code Review: Harden git-sync abbreviated commit verificationOverviewThis PR fixes a real-world robustness issue: git rev-parse HEAD can return an abbreviated commit hash on some systems/configurations, causing the verify lock mode to throw even though the correct commit was checked out. The fix introduces two private helpers (CommitMatchesLockedCommit, SelectResolvedCommit) and extracts the existing hex-character loop into a reusable IsHexString. Code Quality and CorrectnessCommitMatchesLockedCommit (lines 380-394) The logic is sound: exact match first, then prefix-match with safeguards (minimum 12 chars, resolved.Length < locked.Length, both must be hex).
SelectResolvedCommit (lines 367-378) Priority order (full resolved > full checked-out > non-empty resolved > checked-out) is well-reasoned. No issues. Potential inconsistency on line 103 The reference validation on line 103 still uses exact string.Equals while the resolved-commit check now uses the lenient CommitMatchesLockedCommit. Likely intentional (user-supplied references should be explicit), but the asymmetry is worth a comment so it is not silently changed later. Security ConsiderationsThe prefix-match approach is standard git behavior and the 12-char minimum significantly limits the collision window. The condition resolved.Length < locked.Length correctly prevents a resolved full SHA from being accepted as a prefix match of a different locked SHA of the same length. No concerns. Test CoverageRunPipeline_GitSync_LockModeVerify_AcceptsAbbreviatedResolvedCommit
RunPipeline_GitSync_PrefersCheckedOutFullCommitWhenHeadIsAbbreviated
Reflection-based testing: Using BindingFlags.NonPublic is pragmatic; Assert.NotNull(method) catches renames but signature changes throw at Invoke with a less clear error. Pre-existing pattern, no change needed now. Minor Suggestions
SummaryThe core change is correct and well-scoped. The IsHexString extraction is a nice cleanup. Main feedback: a few missing boundary-case tests (particularly the 11-char boundary) and clarity comments on the minimum-length threshold and the asymmetry between reference validation and resolved-commit validation. Logic is solid overall. |
Summary
Tests