zcf 3.1.2 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ ---
2
+ description: Interactively rollback Git branch to historical version; lists branches, versions, then executes reset/revert after confirmation
3
+ allowed-tools: Read(**), Exec(git fetch, git branch, git tag, git log, git reflog, git checkout, git reset, git revert, git switch), Write()
4
+ argument-hint: [--branch <branch>] [--target <rev>] [--mode reset|revert] [--depth <n>] [--dry-run] [--yes]
5
+ # examples:
6
+ # - /git-rollback # Full interactive mode, dry-run
7
+ # - /git-rollback --branch dev # Select dev directly, other interactive
8
+ # - /git-rollback --branch dev --target v1.2.0 --mode reset --yes
9
+ ---
10
+
11
+ # Claude Command: Git Rollback
12
+
13
+ **Purpose**: Safely and visually rollback a specified branch to an older version.
14
+ Defaults to **read-only preview (`--dry-run`)**; actual execution requires `--yes` or interactive confirmation.
15
+
16
+ ---
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # Pure interactive: list branches → select branch → list recent 20 versions → select target → choose reset or revert → confirm
22
+ /git-rollback
23
+
24
+ # Specify branch, other interactive
25
+ /git-rollback --branch feature/calculator
26
+
27
+ # Specify branch and target commit, execute with hard-reset in one go (dangerous)
28
+ /git-rollback --branch main --target 1a2b3c4d --mode reset --yes
29
+
30
+ # Generate revert commit only (non-destructive rollback), preview
31
+ /git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
32
+ ```
33
+
34
+ ### Options
35
+
36
+ | Option | Description |
37
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------ |
38
+ | `--branch <branch>` | Branch to rollback; interactively selected if omitted. |
39
+ | `--target <rev>` | Target version (commit hash, tag, or reflog reference); interactively selects recent `--depth` entries if omitted. |
40
+ | `--mode reset\|revert` | `reset`: Hard rollback history; `revert`: Generate reverse commits keeping history intact. Prompts by default. |
41
+ | `--depth <n>` | List recent n versions in interactive mode (default 20). |
42
+ | `--dry-run` | **Enabled by default**, only preview commands to be executed. |
43
+ | `--yes` | Skip all confirmations and execute directly, suitable for CI/CD scripts. |
44
+
45
+ ---
46
+
47
+ ## Interactive Flow
48
+
49
+ 1. **Sync remote** → `git fetch --all --prune`
50
+ 2. **List branches** → `git branch -a` (local + remote, filter protected branches)
51
+ 3. **Select branch** → User input or parameter
52
+ 4. **List versions** → `git log --oneline -n <depth>` + `git tag --merged` + `git reflog -n <depth>`
53
+ 5. **Select target** → User inputs commit hash / tag
54
+ 6. **Select mode** → `reset` or `revert`
55
+ 7. **Final confirmation** (unless `--yes`)
56
+ 8. **Execute rollback**
57
+ - `reset`: `git switch <branch> && git reset --hard <target>`
58
+ - `revert`: `git switch <branch> && git revert --no-edit <target>..HEAD`
59
+ 9. **Push suggestion** → Prompt whether to `git push --force-with-lease` (reset) or regular `git push` (revert)
60
+
61
+ ---
62
+
63
+ ## Safety Guards
64
+
65
+ - **Backup**: Automatically records current HEAD in reflog before execution, recoverable with `git switch -c backup/<timestamp>`.
66
+ - **Protected branches**: If protected branches like `main` / `master` / `production` are detected with `reset` mode enabled, requires additional confirmation.
67
+ - **--dry-run enabled by default**: Prevents accidental operations.
68
+ - **--force prohibited**: No `--force` provided; if force push needed, manually enter `git push --force-with-lease`.
69
+
70
+ ---
71
+
72
+ ## Use Case Examples
73
+
74
+ | Scenario | Command Example |
75
+ | --------------------------------------------------------------------------- | ---------------------------------------------------------------- |
76
+ | Hotfix patch deployed with bug, need to rollback to tag `v1.2.0` | `/git-rollback --branch release/v1 --target v1.2.0 --mode reset` |
77
+ | Ops colleague pushed debug logs by mistake, need to generate reverse commit | `/git-rollback --branch main --target 3f2e7c9 --mode revert` |
78
+ | Research historical bugs, guide newcomers through branch history | `/git-rollback` (full interactive, dry-run) |
79
+
80
+ ---
81
+
82
+ ## Notes
83
+
84
+ 1. **reset vs revert**
85
+ - **reset** changes history, requires force push and may affect other collaborators, use with caution.
86
+ - **revert** is safer, generates new commits preserving history, but adds one more record.
87
+ 2. **Embedded repositories** often have large binary files; ensure LFS/submodule state consistency before rollback.
88
+ 3. If repository has CI forced validation, rollback may trigger pipelines automatically; confirm control policies to avoid accidental deployment of old versions.
89
+
90
+ ---
@@ -0,0 +1,276 @@
1
+ ---
2
+ description: Manage Git worktrees in project-level ../.zcf/project-name/ directory with smart defaults, IDE integration and content migration
3
+ allowed-tools: Read(**), Exec(git worktree add, git worktree list, git worktree remove, git worktree prune, git branch, git checkout, git rev-parse, git stash, git cp, detect-ide, open-ide, which, command, basename, dirname)
4
+ argument-hint: <add|list|remove|prune|migrate> [path] [-b <branch>] [-o|--open] [--track] [--guess-remote] [--detach] [--checkout] [--lock] [--migrate-from <source-path>] [--migrate-stash]
5
+ # examples:
6
+ # - /git-worktree add feature-ui # create new branch 'feature-ui' from main/master
7
+ # - /git-worktree add feature-ui -o # create worktree and open directly in IDE
8
+ # - /git-worktree add hotfix -b fix/login -o # create new branch 'fix/login' with path 'hotfix'
9
+ # - /git-worktree migrate feature-ui --from main # migrate uncommitted content from main to feature-ui
10
+ # - /git-worktree migrate feature-ui --stash # migrate current stash to feature-ui
11
+ ---
12
+
13
+ # Claude Command: Git Worktree
14
+
15
+ Manage Git worktrees with smart defaults, IDE integration and content migration in structured `../.zcf/project-name/` paths.
16
+
17
+ Execute commands directly and provide concise results.
18
+
19
+ ---
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ # Basic operations
25
+ /git-worktree add <path> # create new branch named <path> from main/master
26
+ /git-worktree add <path> -b <branch> # create new branch with specified name
27
+ /git-worktree add <path> -o # create and open directly in IDE
28
+ /git-worktree list # show all worktree status
29
+ /git-worktree remove <path> # remove specified worktree
30
+ /git-worktree prune # clean invalid worktree references
31
+
32
+ # Content migration
33
+ /git-worktree migrate <target> --from <source> # migrate uncommitted content
34
+ /git-worktree migrate <target> --stash # migrate stash content
35
+ ```
36
+
37
+ ### Options
38
+
39
+ | Option | Description |
40
+ | ------------------ | ------------------------------------------------------ |
41
+ | `add [<path>]` | Add new worktree in `../.zcf/project-name/<path>` |
42
+ | `migrate <target>` | Migrate content to specified worktree |
43
+ | `list` | List all worktrees and their status |
44
+ | `remove <path>` | Remove worktree at specified path |
45
+ | `prune` | Clean invalid worktree references |
46
+ | `-b <branch>` | Create new branch and checkout to worktree |
47
+ | `-o, --open` | Open directly in IDE after creation (skip prompt) |
48
+ | `--from <source>` | Specify migration source path (migrate only) |
49
+ | `--stash` | Migrate current stash content (migrate only) |
50
+ | `--track` | Set new branch to track corresponding remote branch |
51
+ | `--guess-remote` | Auto guess remote branch for tracking |
52
+ | `--detach` | Create detached HEAD worktree |
53
+ | `--checkout` | Checkout immediately after creation (default behavior) |
54
+ | `--lock` | Lock worktree after creation |
55
+
56
+ ---
57
+
58
+ ## What This Command Does
59
+
60
+ 1. **Environment Check**
61
+ - Verify Git repository using `git rev-parse --is-inside-work-tree`
62
+ - Detect whether in main repo or existing worktree for smart path calculation
63
+
64
+ 2. **Smart Path Management**
65
+ - Auto-calculate project name from main repository path using worktree detection
66
+ - Create worktrees in structured `../.zcf/project-name/<path>` directory
67
+ - Handle both main repo and worktree execution contexts correctly
68
+
69
+ ```bash
70
+ # Core path calculation logic for worktree detection
71
+ get_main_repo_path() {
72
+ local git_common_dir=$(git rev-parse --git-common-dir 2>/dev/null)
73
+ local current_toplevel=$(git rev-parse --show-toplevel 2>/dev/null)
74
+
75
+ # Check if in worktree
76
+ if [[ "$git_common_dir" != "$current_toplevel/.git" ]]; then
77
+ # In worktree, derive main repo path from git-common-dir
78
+ dirname "$git_common_dir"
79
+ else
80
+ # In main repository
81
+ echo "$current_toplevel"
82
+ fi
83
+ }
84
+
85
+ MAIN_REPO_PATH=$(get_main_repo_path)
86
+ PROJECT_NAME=$(basename "$MAIN_REPO_PATH")
87
+ WORKTREE_BASE="$MAIN_REPO_PATH/../.zcf/$PROJECT_NAME"
88
+
89
+ # Always use absolute path to prevent nesting issues
90
+ ABSOLUTE_WORKTREE_PATH="$WORKTREE_BASE/<path>"
91
+ ```
92
+
93
+ **Critical Fix**: Always use absolute paths when creating worktrees from within existing worktrees to prevent path nesting issues like `../.zcf/project/.zcf/project/path`.
94
+
95
+ 3. **Worktree Operations**
96
+ - **add**: Create new worktree with smart branch/path defaults
97
+ - **list**: Display all worktrees with branches and status
98
+ - **remove**: Safely remove worktree and clean references
99
+ - **prune**: Clean orphaned worktree records
100
+
101
+ 4. **Smart Defaults**
102
+ - **Branch creation**: When no `-b` specified, create new branch using path name
103
+ - **Base branch**: New branches created from main/master branch
104
+ - **Path resolution**: Use branch name as path when unspecified
105
+ - **IDE integration**: Auto-detect and prompt for IDE opening
106
+
107
+ 5. **Content Migration**
108
+ - Migrate uncommitted changes between worktrees
109
+ - Apply stash content to target worktree
110
+ - Safety checks to prevent conflicts
111
+
112
+ 6. **Safety Features**
113
+ - **Path conflict prevention**: Check for existing directories before creation
114
+ - **Branch checkout validation**: Ensure branches aren't already in use
115
+ - **Absolute path enforcement**: Prevent nested `.zcf` directories when in worktree
116
+ - **Auto-cleanup on removal**: Clean both directory and git references
117
+ - **Clear status reporting**: Display worktree locations and branch status
118
+
119
+ 7. **Environment File Handling**
120
+ - **Auto-detection**: Scan `.gitignore` for environment variable file patterns
121
+ - **Smart copying**: Copy `.env` and `.env.*` files that are listed in `.gitignore`
122
+ - **Exclusion logic**: Skip `.env.example` and other template files
123
+ - **Permission preservation**: Maintain original file permissions and timestamps
124
+ - **User feedback**: Provide clear status on copied environment files
125
+
126
+ ```bash
127
+ # Environment file copying implementation
128
+ copy_environment_files() {
129
+ local main_repo="$MAIN_REPO_PATH"
130
+ local target_worktree="$ABSOLUTE_WORKTREE_PATH"
131
+ local gitignore_file="$main_repo/.gitignore"
132
+
133
+ # Check if .gitignore exists
134
+ if [[ ! -f "$gitignore_file" ]]; then
135
+ return 0
136
+ fi
137
+
138
+ local copied_count=0
139
+
140
+ # Detect .env file
141
+ if [[ -f "$main_repo/.env" ]] && grep -q "^\.env$" "$gitignore_file"; then
142
+ cp "$main_repo/.env" "$target_worktree/.env"
143
+ echo "✅ Copied .env"
144
+ ((copied_count++))
145
+ fi
146
+
147
+ # Detect .env.* pattern files (excluding .env.example)
148
+ for env_file in "$main_repo"/.env.*; do
149
+ if [[ -f "$env_file" ]] && [[ "$(basename "$env_file")" != ".env.example" ]]; then
150
+ local filename=$(basename "$env_file")
151
+ if grep -q "^\.env\.\*$" "$gitignore_file"; then
152
+ cp "$env_file" "$target_worktree/$filename"
153
+ echo "✅ Copied $filename"
154
+ ((copied_count++))
155
+ fi
156
+ fi
157
+ done
158
+
159
+ if [[ $copied_count -gt 0 ]]; then
160
+ echo "📋 Copied $copied_count environment file(s) from .gitignore"
161
+ fi
162
+ }
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Enhanced Features
168
+
169
+ ### IDE Integration
170
+
171
+ - **Auto-detection**: VS Code → Cursor → WebStorm → Sublime Text → Vim
172
+ - **Smart prompting**: Ask to open in IDE after worktree creation
173
+ - **Direct open**: Use `-o` flag to skip prompt and open immediately
174
+ - **Custom configuration**: Configurable via git config
175
+
176
+ ### Content Migration System
177
+
178
+ ```bash
179
+ # Migrate uncommitted changes
180
+ /git-worktree migrate feature-ui --from main
181
+ /git-worktree migrate hotfix --from ../other-worktree
182
+
183
+ # Migrate stash content
184
+ /git-worktree migrate feature-ui --stash
185
+ ```
186
+
187
+ **Migration Flow**:
188
+
189
+ 1. Verify source has uncommitted content
190
+ 2. Ensure target worktree is clean
191
+ 3. Show changes to be migrated
192
+ 4. Execute safe migration using git commands
193
+ 5. Confirm results and suggest next steps
194
+
195
+ ---
196
+
197
+ ## Examples
198
+
199
+ ```bash
200
+ # Basic usage
201
+ /git-worktree add feature-ui # create new branch 'feature-ui' from main/master
202
+ /git-worktree add feature-ui -b my-feature # create new branch 'my-feature' with path 'feature-ui'
203
+ /git-worktree add feature-ui -o # create and open in IDE directly
204
+
205
+ # Content migration scenarios
206
+ /git-worktree add feature-ui -b feature/new-ui # create new feature worktree
207
+ /git-worktree migrate feature-ui --from main # migrate uncommitted changes
208
+ /git-worktree migrate hotfix --stash # migrate stash content
209
+
210
+ # Management operations
211
+ /git-worktree list # view all worktrees
212
+ /git-worktree remove feature-ui # remove unneeded worktree
213
+ /git-worktree prune # clean invalid references
214
+ ```
215
+
216
+ **Example Output**:
217
+
218
+ ```
219
+ ✅ Worktree created at ../.zcf/project-name/feature-ui
220
+ ✅ Copied .env
221
+ ✅ Copied .env.local
222
+ 📋 Copied 2 environment file(s) from .gitignore
223
+ 🖥️ Open ../.zcf/project-name/feature-ui in IDE? [y/n]: y
224
+ 🚀 Opening ../.zcf/project-name/feature-ui in VS Code...
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Directory Structure
230
+
231
+ ```
232
+ parent-directory/
233
+ ├── your-project/ # main project
234
+ │ ├── .git/
235
+ │ └── src/
236
+ └── .zcf/ # worktree management
237
+ └── your-project/ # project worktrees
238
+ ├── feature-ui/ # feature branch
239
+ ├── hotfix/ # hotfix branch
240
+ └── debug/ # debug worktree
241
+ ```
242
+
243
+ ---
244
+
245
+ ## Configuration
246
+
247
+ ### IDE Configuration
248
+
249
+ - Supports VS Code, Cursor, WebStorm, Sublime Text, Vim
250
+ - Configurable via git config for custom IDEs
251
+ - Auto-detection with priority-based selection
252
+
253
+ ### Custom IDE Setup
254
+
255
+ ```bash
256
+ # Configure custom IDE
257
+ git config worktree.ide.custom.sublime "subl %s"
258
+ git config worktree.ide.preferred "sublime"
259
+
260
+ # Control auto-detection
261
+ git config worktree.ide.autodetect true # default
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Notes
267
+
268
+ - **Performance**: Worktrees share `.git` directory, saving disk space
269
+ - **Safety**: Path conflict prevention and branch checkout validation
270
+ - **Migration**: Only uncommitted changes; use `git cherry-pick` for commits
271
+ - **IDE requirement**: Command-line tools must be in PATH
272
+ - **Cross-platform**: Supports Windows, macOS, Linux
273
+ - **Environment files**: Automatically copies environment files listed in `.gitignore` to new worktrees
274
+ - **File exclusions**: Template files like `.env.example` are preserved in main repo only
275
+
276
+ ---