Repository navigation
fix(target): hash plain source directories when --target-source-path is not a git repo - #576
Open
ParthMozarkar wants to merge 1 commit into
Open
ParthMozarkar wants to merge 1 commit into
ParthMozarkar wants to merge 1 commit into
Conversation
…is not a git repo Target.get_repo_hash() opened the user-provided source path with git.Repo(), so a plain directory (for example an unpacked release tarball) crashed build-target and run with InvalidGitRepositoryError, and a freshly initialized repository with no commits crashed with ValueError. When the path is not a git work tree, or HEAD has no commit, fall back to hashing the directory contents (relative paths, file modes and bytes, skipping .git) and print a warning. The hashing is shared with the existing project-directory hash, whose output is unchanged. Git repositories keep their commit-based hashes, so existing image tags and build caches stay valid. A missing path still raises. Document how the target image tag is derived in target-project.md. Closes ossf#567 Signed-off-by: ParthMozarkar <greatparth21@gmail.com>
Author
|
@azchin could you take a look when you have time? Happy to switch to a clear error instead if you'd rather require git for this flag. |
This branch has not been deployed
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.
Summary
Target.get_repo_hash()opened the--target-source-pathdirectory withgit.Repo(), so a plain directory (e.g. an unpacked release tarball) crashedbuild-targetandrunwithInvalidGitRepositoryError, and a freshlygit init-ed repo with no commits crashed withValueError.When the path isn't a git work tree, or HEAD has no commit, this now falls back to hashing the directory contents (relative paths, file modes and bytes, skipping
.git) and prints a warning. The hashing is moved into a shared_hash_directory_contents()helper that__get_proj_hash()also uses; its output is unchanged. Git repositories keep their commit-based hash, so existing image tags and build caches stay valid. A missing path still raises.User Impact
--target-source-pathnow accepts plain source directories and uncommitted repos.docs/config/target-project.mddocuments how the target image tag is derived. No config or CLI changes; no migration needed.Release Note / Changelog
CHANGELOG.md([Unreleased]) for user-facing changesValidation
Added
oss_crs/tests/unit/test_target_repo_hash.py(16 tests; 11 failed before the fix):.gitcontents ignoredNoSuchPathError--target-source-path) pinned to its pre-change valueuv run verify: all checks pass (ruff check, ruff format, pyright, unit tests, libCRS unit tests).Checklist
Closes #567