#2

feat: add --keep-git flag to preserve .git directories

Openaryasaatvikwants to merge intofrom

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 keepGit to OpensrcSettings in src/lib/settings.ts.
  • Implemented getKeepGitPermission() and setKeepGitPermission() helper functions.
  • Modified fetchSource() and fetchRepoSource() in src/lib/git.ts to conditionally skip .git removal.
  • Updated the fetch command and main CLI entry point to support the --keep-git flag.
  • Centralized FetchOptions in src/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
}

Activity

3
ctate9mo ago

Thanks for the contribution!

I think there's a bug that needs fixing before this can merge:

The --modify flag is broken. Commander maps --modify to options.modify, but you're now passing options directly to fetchCommand which expects allowModifications. This silently breaks the existing flag

Also, setKeepGitPermission is exported but never called - either remove it or wire it up to persist the setting via CLI like --modify does