gitvan
Version:
Autonomic Git-native development automation platform with AI-powered workflows
157 lines (119 loc) • 4.81 kB
Markdown
for GitVan v2, refactored from a monolithic structure into focused, testable factory modules.
The composables follow a factory pattern where each module exports a factory function that accepts shared dependencies:
```javascript
export default function makeX(base, run, runVoid, toArr) {
return { /* functions */ }
}
```
```
src/composables/
├── git/
│ ├── index.mjs
│ ├── runner.mjs
│ ├── repo.mjs
│ ├── commits.mjs
│ ├── diff.mjs
│ ├── branches.mjs
│ ├── tags.mjs
│ ├── notes.mjs
│ ├── refs.mjs
│ ├── worktrees.mjs
│ ├── remotes.mjs
│ ├── merge_rebase_reset.mjs
│ ├── stash.mjs
│ ├── cherry_revert.mjs
│ └── plumbing.mjs
├── index.mjs
├── worktree.mjs
├── template.mjs
├── notes.mjs
├── job.mjs
├── event.mjs
├── schedule.mjs
├── receipt.mjs
├── lock.mjs
└── registry.mjs
```
```javascript
import { useGit } from "./src/composables/git/index.mjs";
const git = useGit();
```
```javascript
import { useGit } from "./src/composables/index.mjs";
const git = useGit();
```
```javascript
import makeRepo from "./src/composables/git/repo.mjs";
const mockBase = { cwd: "/test", env: {} };
const mockRun = async (args) => "test-output";
const mockRunVoid = async (args) => {};
const mockToArr = (x) => Array.isArray(x) ? x : [x];
const repo = makeRepo(mockBase, mockRun, mockRunVoid, mockToArr);
```
- **Release Helpers**: `shortlog(range)`, `trailers(range)`
- **Path Filtering**: `pathsChanged(globs, from, to)`
- **Notes Default**: `NOTES_REF` constant with defaulting
- **Tag Convenience**: `pushTags(remote)`
- **Remote Detection**: `defaultRemote()`
- `TZ=UTC` - UTC timezone
- `LANG=C` - C locale
- `LC_ALL=C` - C locale for all categories
- `GIT_TERMINAL_PROMPT=0` - Disable terminal prompts
- `head()` → `headSha()` (more descriptive)
- `repoRoot()` → `root()` (shorter)
- `statusPorcelain()` → `status()` (simplified)
- `catFilePretty()` → `catFile()` (simplified)
- [Composables Index](../docs/composables/index.md) - Architecture overview
- [Git API Reference](../docs/composables/git-api.md) - Detailed function documentation
- [Migration Guide](../docs/composables/migration-guide.md) - Upgrade from v1
- [Quick Reference](../docs/composables/quick-reference.md) - Cheat sheet
Each module can be tested independently:
```javascript
import makeRepo from "./src/composables/git/repo.mjs";
// Mock dependencies
const mockBase = { cwd: "/test", env: {} };
const mockRun = async (args) => "test-output";
const mockRunVoid = async (args) => {};
const mockToArr = (x) => Array.isArray(x) ? x : [x];
// Create instance
const repo = makeRepo(mockBase, mockRun, mockRunVoid, mockToArr);
// Test functions
const root = await repo.root(); // Uses mockRun
```
- Smaller, focused modules (~80 lines each)
- Clear separation of concerns
- Easier to understand and modify
### Testability
- Test individual modules in isolation
- Mock dependencies easily
- Faster test execution
### Extensibility
- Add new Git operations easily
- Compose only what you need
- Better tree-shaking support
### Performance
- Modular loading
- Efficient object composition
- Deterministic behavior
## Migration from v1
See the [Migration Guide](../docs/composables/migration-guide.md) for detailed instructions on upgrading from the monolithic version.
Key changes:
1. Update import paths
2. Rename functions (see API changes above)
3. Take advantage of new features
4. Update tests to use modular approach
This directory contains the modular composables