feat(config): support remote preset resolution via git clone --depth 1#43
feat(config): support remote preset resolution via git clone --depth 1#43
git clone --depth 1#43Conversation
Local-only preset loading (extends field) could not resolve remote references like `github:org/[email protected]` or generic git URLs. Teams sharing presets across repositories had no way to reference them. Add git clone --depth 1 based remote preset fetching with: - `github:org/repo@version` shorthand parsing (SHA, tag, branch, latest) - Generic git URL support (HTTPS and SSH, with optional @ref suffix) - Cache at $XDG_CACHE_HOME/runok/presets/ with SHA256-keyed directories - TTL-based cache (24h default, RUNOK_CACHE_TTL override, SHA permanent) - Stale cache: git fetch update with fallback to old cache on error - Mutable reference warnings recommending commit SHA pinning - GIT_DIR/GIT_INDEX_FILE env sanitization for worktree compatibility - GitClient trait abstraction with MockGitClient for testability - Unified load_preset() dispatcher for local and remote references Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary of ChangesHello @fohte, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the configuration system by enabling the resolution of presets from remote Git repositories. It introduces a comprehensive caching layer to optimize performance and reliability for remote presets, supporting various reference types including GitHub shorthand and direct Git URLs. The underlying Git operations are carefully abstracted and environment variables are sanitized, ensuring both testability and broad compatibility. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Devin review identified three issues:
1. `GitUrl` with commit SHA passed SHA as `--branch` to `git clone`,
which fails because `--branch` only accepts branch/tag names.
Now SHA detection is based on `params.git_ref` instead of only
checking the `GitHub` variant, so both `github:` and git URL
references handle SHA correctly.
2. Stale cache for `Latest` references ran `git fetch` but skipped
`git checkout`, leaving the working tree at the old commit while
updating metadata. Now always checks out `FETCH_HEAD` when no
explicit git_ref is specified.
3. HTTPS URLs with userinfo `@` (e.g., `https://user@host/...`) were
misparsed because `rfind('@')` matched the userinfo `@` instead of
the ref separator. Now only searches for `@` in the URL path portion
after the host.
1. Add `--` separator to `git clone`, `git fetch`, and `git checkout` commands to prevent argument injection via crafted ref strings (e.g., `--upload-pack=...`). 2. Sanitize URLs in error messages to strip credentials from the authority component (`user:pass@host` → `***@host`). 3. Use `Self::git_command()` helper in `clone_shallow` to avoid duplicating env sanitization logic. 4. Remove unused fields from `GitCall` enum and the `#[expect(dead_code)]` annotation. Only `branch` and `git_ref` are used in test assertions. 5. Remove unused `_reference` and `_cache` parameters from `handle_cache_miss` and `handle_stale_cache`. 6. Replace `Vec::remove(0)` with `VecDeque::pop_front()` in `MockGitClient` for O(1) queue operations.
1. Move git_ref before `--` in `git checkout` so it is interpreted as a tree-ish (branch/tag/commit), not a pathspec. `git checkout -- ref` tries to restore a file named "ref" from the index, which is wrong. 2. Extract inner message from PresetError::GitClone when re-wrapping clone/checkout errors in handle_cache_miss. Previously `e.to_string()` produced "git clone failed for '...': <msg>" which was nested inside another "git clone failed for '...': ..." making the output redundant.
`git fetch --depth 1 origin main` updates FETCH_HEAD and origin/main but not the local main branch. If the working tree is already on main, `git checkout main` is a no-op and the files stay at the old commit. Always checking out FETCH_HEAD ensures the working tree reflects the just-fetched content regardless of the current branch state.
A shallow clone without --branch only has the default branch tip. The requested commit SHA is not available, so `git checkout <sha>` fails. Instead, explicitly `git fetch origin <sha>` to retrieve the commit object, then `git checkout FETCH_HEAD` to update the working tree.
Why
extendsfieldWhat
github:org/repo@versionshorthand and generic HTTPS/SSH git URLs for remote preset resolutiongit clone --depth 1, delegating authentication to the machine's git configuration (lefthook approach)$XDG_CACHE_HOME/runok/presets/with SHA256-keyed directories (24-hour TTL; commit SHA references are cached permanently)git fetchto update stale caches, falling back to the old cache on failureGIT_DIR/GIT_INDEX_FILEenvironment variables for worktree compatibilityGitClienttrait, enablingMockGitClient-based testing