#2
feat: add --keep-git flag to preserve .git directories
Summary
This PR adds a --keep-git flag and a corresponding keepGit persistent setting to opensrc.
Problem
By default, opensrc removes the .git directory after cloning to save space. While efficient, this prevents subsequent git operations (like git blame, git log, or git rev-parse) which are useful for developer tools and AI agents that need to construct GitHub permalinks or inspect code history.
Changes
- Added
keepGittoOpensrcSettingsinsrc/lib/settings.ts. - Implemented
getKeepGitPermission()andsetKeepGitPermission()helper functions. - Modified
fetchSource()andfetchRepoSource()insrc/lib/git.tsto conditionally skip.gitremoval. - Updated the
fetchcommand and main CLI entry point to support the--keep-gitflag. - Centralized
FetchOptionsinsrc/types.ts. - Updated the README with documentation for the new flag and setting.
Usage
# CLI flag
opensrc zod --keep-git
# Persistent setting in opensrc/settings.json
{
"keepGit": true
}
Thanks for the contribution!
I think there's a bug that needs fixing before this can merge:
The
--modifyflag is broken. Commander maps--modifytooptions.modify, but you're now passing options directly to fetchCommand which expects allowModifications. This silently breaks the existing flagAlso,
setKeepGitPermissionis exported but never called - either remove it or wire it up to persist the setting via CLI like--modifydoes