Skip to content

Update git resources #207

@dca123

Description

@dca123

I clone in projects that get frequent updates. So i needed to go into the git folder inside btca and sync manually. I added a command called btca sync repos on my own fork(reference -
main...dca123:better-context:feat/sync-repos). Hope you find it useful !

Prompt You are working in the btca monorepo (Bun-only). Implement a new CLI command: - Command: `btca sync repos [name...]` - Purpose: sync/refresh the cached on-disk git clones for configured git resources (resources added via `btca add ... --type git`), in either the global cache or the project-local cache. Requirements 1) CLI wiring - Add a new command module under `apps/cli/src/commands/` (e.g. `sync.ts`) exporting a commander `Command` for `sync`. - Register the new top-level command in `apps/cli/src/index.ts`. 2) UX + flags - Subcommand: `btca sync repos [name...]` - Optional positional args: one or more resource names. If omitted, sync all configured git resources in the chosen scope. - Scope flags (mutually exclusive): `--local` and `--global`. - Default scope if neither flag is set: - If `./btca.config.jsonc` exists in CWD: default to local scope - Otherwise: default to global scope - If user supplies any unknown resource name(s), fail with a helpful message and suggest running `btca resources`. - Only git resources are eligible; non-git resources are ignored for “sync all”, but if a user explicitly names a resource that isn’t a git resource, treat that as an error. 3) Config + scope resolution (match server behavior closely) - Read global config from `~/.config/btca/btca.config.jsonc` (if missing, treat as empty). - Read project config from `./btca.config.jsonc` (local scope requires it; if missing, error). - Parse JSONC (support // and /* */ comments + trailing commas). - Local scope uses merged resources: global + project, with project overriding global by resource name. - Global scope uses global resources only. 4) Data directory + resources directory resolution - Determine the data directory similarly to server config rules: - Global scope: `global.dataDirectory` or default `~/.local/share/btca` - If relative, resolve relative to `~/.config/btca` - Local scope: `project.dataDirectory` else `global.dataDirectory` else default `~/.local/share/btca` - If project does not specify `dataDirectory` and a legacy `.btca/` directory exists in CWD, treat `.btca` as the local data directory (legacy fallback, no config writes). - If relative, resolve relative to `process.cwd()` - The repos cache root is `/resources`. 5) Repo folder naming - Cache directory for each resource is `/` (must match server’s resource cloning convention). 6) Git operations - Fail fast if `git` is not available on PATH. - For each selected git resource: - If `/.git` does not exist: clone into repoDir. - If repo exists: fetch + reset hard to origin/branch, but detect “unchanged”: - After fetch, compare `HEAD` hash to `origin/` hash. - If equal: report `unchanged` (do not claim updated). - If different: hard reset and report `updated`. - Branch defaults to `main` if not specified. - If `searchPath`/`searchPaths` is present, support sparse checkout: - Clone with sparse enabled (no checkout), then set sparse paths, then checkout. - On update, re-apply sparse paths and checkout. 7) Output + exit codes - Print chosen scope and the resolved resources directory. - Print a warning that this refreshes cached clones and may discard local edits inside the cache. - For each resource: print a single status line: `cloned`, `updated`, `unchanged`, or `failed`. - End with a summary line including counts for Updated/Unchanged/Cloned/Failed. - Exit non-zero if any failures occurred. 8) Docs (required in this repo) - Update `apps/docs/guides/cli-reference.mdx` to document: - `btca sync repos [name...]` - `--local` / `--global` and default-scope behavior - The fact it does fetch + hard reset for cached clones - Sparse checkout behavior - Update `apps/docs/btca.spec.md` with a new section for the command. 9) Verification - Run: `bun run format:cli` and `bun run check:cli` - Run docs formatting + validation using the repo’s docs scripts. Constraints - Do NOT add any additional CLI aliases; only `btca`. - Do NOT add any shell/zsh wrapper changes. - Keep behavior consistent with existing repo conventions and printing style. Return a short list of touched files and example invocations to verify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions