feat: add --init and --commit flags for git initialization after clone#63
Conversation
ReviewOverviewAdds Strengths
Issues / Risks1. Watch mode will fail on the second tick ( 2. 3. Blob target without a directory pollutes CWD. 4. Hard-coded 5. 6. Help-text alignment. TestsFour new tests cover tree/blob × init/commit happy paths. Gaps worth adding:
Security
RecommendationApprove after addressing #1 (watch-mode re-commit) and #2 (graceful failure when git identity is unset). The other items are polish. |
|
One more thought: there's no default commit message right now — gitpick owner/repo --commit # → "init awesomeness" |
|
Thanks for the review!! I've pushed updates addressing all your points:
Let me know if something is still missing. 🙏 |
b2bf739 to
858436a
Compare
… clone Closes nrjdalal#61. gitpick strips `.git` when cloning; these flags let users start tracking their scaffolded output without extra manual steps. - --init: initialize the cloned output as a new git repository (idempotent — skips if .git already exists). For a blob, inits the parent directory. - --auto-commit: create an initial commit with message "chore: gitpick'ed". - --commit <msg>: create an initial commit with <msg> (empty falls back to the default). Both committing flags imply --init. `--commit` is a plain required-value string flag, so a message beginning with `-`, a stray URL, or an empty value can't be silently mis-parsed. Safety / robustness: - refuses to initialize the current working directory (file or directory); - stages only the cloned file / picked paths / cloned tree (interactive picks stage the exact copied files, not the picked directory), so unrelated contents of a pre-existing target directory are never swept into the commit; - an empty pick prints a notice and skips the commit rather than `git add .`; - `git add --force` so a `.gitignore` that rode along in the clone can't abort staging of files the user explicitly asked to pick; - large picks are staged via a NUL-delimited pathspec file (--pathspec-from-file, git >= 2.25) so a huge tree can't overflow the argv limit (E2BIG), falling back to argv `git add` on older git; separators normalized to "/" so Windows-cloned paths still match git's index; - any git failure (init or commit) is surfaced but never undoes the already successful clone; skip warnings show under --tree and are silenced only by --quiet. Refactor: the git plumbing lives in bin/utils/init-git-repo.ts (keeping index.ts at orchestration altitude per AGENTS.md); temp-dir/file naming is a shared tempName() helper; the two interactive copy loops share a copySelected() helper so the staging-scope logic can't drift between them. Also reorders the CLI options help (code + README) to the maintainer's layout. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Ships the --init / --auto-commit / --commit git-init feature as a new major. Version differs from the npm `latest` tag, so merging this to `main` triggers a `latest` publish via release.yml. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
858436a to
332bca1
Compare
Adds flags to turn a fresh clone into a git repo — no extra manual steps.
Closes #61.
Motivation
gitpickintentionally strips.gitwhen cloning (great for scaffolding), but users who want to track their own changes had to rungit init(and optionallygit add+git commit) after every clone. This automates it.Flags
--init— initialize the cloned output as a new git repository.git initin the target; blob → in the parent directory..gitexists); refuses to init the current working directory.--auto-commit— create an initial commit with the default messagechore: gitpick'ed(implies--init).--commit <msg>— create an initial commit with<msg>(implies--init). A plain required-value string flag, so a message starting with-, a stray URL, or an empty value can't be silently mis-parsed.Safety — staging is scoped to exactly what was cloned
--pathspec-from-file, so unrelated contents of a pre-existing-otarget are never swept in, and huge picks can't overflow the argv limit (separators normalized to/for Windows);git add .;Usage
Tests
--init(tree/blob),--auto-commitdefault message,--commit <msg>(tree/blob), idempotency, missing-identity error surfacing, cwd refusal, pre-existing-dir staging scope, and the empty-pick guard. Full suite green.