Validate git ref and repo values to reject dash-prefixed inputs#4598
Open
aravindtga wants to merge 2 commits into
Open
Validate git ref and repo values to reject dash-prefixed inputs#4598aravindtga wants to merge 2 commits into
aravindtga wants to merge 2 commits into
Conversation
Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
✅ Deploy Preview for kptdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds early validation to reject git repo/ref inputs that start with -, preventing them from being misinterpreted as git command-line options and surfacing clearer, earlier errors to users.
Changes:
- Added
--prefix validation forrepo/refinget,fetch,update, andpkgupdateentry points. - Added a defensive validation layer in
internal/gitutil.GitUpstreamRepo.cacheRepoto reject dash-prefixed URIs/refs before invoking git. - Added a unit test to ensure flag-like refs are rejected.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/lib/util/get/get.go | Rejects dash-prefixed repo/ref during get defaulting/validation. |
| pkg/lib/util/fetch/fetch.go | Rejects dash-prefixed repo/ref during fetch validation. |
| pkg/lib/update/update.go | Rejects dash-prefixed upstream repo/ref during update execution. |
| pkg/lib/kptops/pkgupdate.go | Rejects dash-prefixed upstream repo/ref in the pkgupdate wrapper. |
| internal/gitutil/gitutil.go | Adds catch-all validation in cacheRepo for URI/refs before running git. |
| internal/gitutil/gitutil_test.go | Adds test coverage for rejecting flag-like refs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
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.
Description
-across all command entry points (get,fetch,update,pkgupdate) and in the internalgitutil.cacheRepofunction.-is not a valid git ref. Accepting such values leads to confusing git errors downstream. Rejecting them early provides a clear error message to the user.DefaultValues,validate,Run) now checks for-prefixes and returns an early, clear error. Additionally,cacheRepoininternal/gitutilvalidates all refs and URIs before executing any git commands, acting as a catch-all for all callers regardless of entry point.Type of Change
Checklist
AI Disclosure
If so, please describe how: