Skip to content

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

Open
aryasaatvik wants to merge 2 commits intovercel-labs:mainfrom
aryasaatvik:feature/keep-git-flag
Open

feat: add --keep-git flag to preserve .git directories#2
aryasaatvik wants to merge 2 commits intovercel-labs:mainfrom
aryasaatvik:feature/keep-git-flag

Conversation

@aryasaatvik
Copy link

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
}

…it option to OpensrcSettings interface in settings.ts\n- Add getKeepGitPermission and setKeepGitPermission functions\n- Modify fetchSource and fetchRepoSource to respect keepGit option\n- Add --keep-git CLI flag to fetch command\n- Support both CLI flag and settings.json configuration\n- Default behavior remains removing .git for space efficiency\n\nThis enables tools to perform git operations (blame, log, rev-parse) on \ncloned repositories without network calls.
@ctate
Copy link
Collaborator

ctate commented Feb 2, 2026

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments