cascade-cli 0.1.152

Stacked diffs CLI for Bitbucket Server
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
# 🔧 Troubleshooting Guide

This guide helps you diagnose and fix common issues with Cascade CLI.

## 🚨 **Quick Diagnostic**

Before diving into specific issues, run the built-in diagnostics:

```bash
# Run comprehensive health check
ca doctor

# Get detailed system information
ca doctor --verbose

# Show configuration
ca config list

# Check Git status
git status
```

---

## 📋 **Common Issues**

### **🔴 Installation & Setup**

#### **"command not found: cc"**

**Symptoms:**
```bash
$ ca --version
bash: cc: command not found
```

**Solutions:**

1. **Check if binary exists:**
   ```bash
   # If installed via cargo
   ls ~/.cargo/bin/cc
   
   # If built from source
   ls target/release/cc
   ```

2. **Fix PATH:**
   ```bash
   # Add to PATH temporarily
   export PATH="$HOME/.cargo/bin:$PATH"
   
   # Make permanent (bash)
   echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
   source ~/.bashrc
   
   # Make permanent (zsh)
   echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
   source ~/.zshrc
   ```

3. **Reinstall:**
   ```bash
   # Via cargo
   cargo install --path . --force
   
   # Or rebuild
   cargo build --release
   cp target/release/ca ~/.local/bin/
   ```

#### **Rust compilation errors**

**Symptoms:**
```
error: linking with `ca` failed: exit status: 1
```

**Solutions:**

1. **Update Rust:**
   ```bash
   rustup update
   rustc --version  # Should be 1.82+
   ```

2. **Install system dependencies:**
   ```bash
   # Ubuntu/Debian
   sudo apt update
   sudo apt install build-essential pkg-config libssl-dev
   
   # macOS
   xcode-select --install
   
   # CentOS/RHEL
   sudo yum groupinstall "Development Tools"
   sudo yum install openssl-devel
   ```

3. **Clear cache and rebuild:**
   ```bash
   cargo clean
   cargo build --release
   ```

#### **Permission denied errors**

**Symptoms:**
```bash
$ ca --version
Permission denied
```

**Solutions:**

1. **Fix permissions:**
   ```bash
   chmod +x ~/.cargo/bin/cc
   ```

2. **Install to user directory:**
   ```bash
   cargo install --path . --root ~/.local
   export PATH="$HOME/.local/bin:$PATH"
   ```

### **🔴 Configuration Issues**

#### **"Repository not initialized"**

**Symptoms:**
```
Error: Repository is not initialized for Cascade CLI
```

**Solutions:**

1. **Check if in Git repository:**
   ```bash
   git status
   # Should show repository status, not "not a git repository"
   ```

2. **Initialize Cascade CLI:**
   ```bash
   ca init --bitbucket-url https://your-bitbucket.com
   # Or use setup wizard
   ca setup
   ```

3. **Fix corrupted configuration:**
   ```bash
   rm -rf .cascade/
   ca init --force
   ```

#### **Bitbucket connection failures**

**Symptoms:**
```
Error: Failed to connect to Bitbucket: HTTP 401 Unauthorized
Error: Failed to connect to Bitbucket: Connection timeout
```

**Solutions:**

1. **Verify credentials:**
   ```bash
   ca config get bitbucket.token
   ca config get bitbucket.url
   
   # Test manually
   curl -H "Authorization: Bearer YOUR_TOKEN" \
        "https://your-bitbucket.com/rest/api/1.0/projects"
   ```

2. **Check Personal Access Token:**
   - Token must have **Repository Write** permissions
   - Token must not be expired
   - Check Bitbucket → Settings → Personal Access Tokens

3. **Network issues:**
   ```bash
   # Check DNS resolution
   nslookup your-bitbucket.com
   
   # Test connectivity
   ping your-bitbucket.com
   
   # Check proxy settings
   echo $HTTP_PROXY
   echo $HTTPS_PROXY
   ```

4. **Corporate firewall/proxy:**
   ```bash
   # Configure Git for proxy
   git config --global http.proxy http://proxy.company.com:8080
   git config --global https.proxy https://proxy.company.com:8080
   
   # Set environment variables
   export HTTP_PROXY=http://proxy.company.com:8080
   export HTTPS_PROXY=https://proxy.company.com:8080
   ```

#### **Invalid project/repository settings**

**Symptoms:**
```
Error: Project 'INVALID' not found
Error: Repository 'invalid-repo' not found in project 'PROJECT'
```

**Solutions:**

1. **List available projects:**
   ```bash
   curl -H "Authorization: Bearer YOUR_TOKEN" \
        "https://your-bitbucket.com/rest/api/1.0/projects" | jq '.values[].key'
   ```

2. **List repositories in project:**
   ```bash
   curl -H "Authorization: Bearer YOUR_TOKEN" \
        "https://your-bitbucket.com/rest/api/1.0/projects/PROJECT/repos" | jq '.values[].name'
   ```

3. **Auto-detect from Git remote:**
   ```bash
   git remote -v
   # Use the setup wizard to auto-detect
   ca setup --force
   ```

### **🔴 Stack Management Issues**

#### **"No active stack" errors**

**Symptoms:**
```
Error: No active stack found
```

**Solutions:**

1. **Check existing stacks:**
   ```bash
   ca stacks list
   ```

2. **Create or activate a stack:**
   ```bash
   # Create new stack
   ca stacks create my-feature --base main
   
   # Or activate existing stack
   ca stacks switch existing-stack-name
   ```

3. **Recover from corruption:**
   ```bash
   # Check stack metadata
   ls .cascade/stacks/
   
   # Validate stack integrity
   ca stacks validate
   
   # Force create new stack if needed
   ca stacks create recovery-stack --base main --force
   ```

#### **Stack synchronization failures**

**Symptoms:**
```
Error: Failed to sync stack: merge conflicts detected
Error: Base branch 'main' not found
```

**Solutions:**

1. **Resolve merge conflicts:**
   ```bash
   # Check conflict status
   git status
   
   # Resolve conflicts manually
   git add .
   ca rebase continue
   
   # Or abort and try different strategy
   ca rebase abort
   ca stacks sync --strategy merge
   ```

2. **Update base branch:**
   ```bash
   # Fetch latest changes
   git fetch origin
   
   # Ensure base branch exists
   git branch -r | grep origin/main
   
   # Update local base
   git checkout main
   git pull origin main
   
   # Try sync again
   ca stacks sync
   ```

3. **Stack corruption recovery:**
   ```bash
   # Backup current work
   git stash
   
   # Reset stack to known good state
   ca stack  # Note commit hashes
   git checkout main
   git pull origin main
   
   # Recreate stack manually
   ca stacks create recovery --base main
   git cherry-pick COMMIT_HASH_1
   ca stacks push
   git cherry-pick COMMIT_HASH_2
   ca stacks push
   ```

#### **Pull request creation failures**

**Symptoms:**
```
Error: Failed to create pull request: title cannot be empty
Error: Failed to create pull request: source branch not found
```

**Solutions:**

1. **Check commit exists:**
   ```bash
   git log --oneline -n 5
   ca stack
   ```

2. **Verify branch state:**
   ```bash
   # Check current branch
   git branch
   
   # Ensure commits are pushed to remote
   git push origin current-branch
   ```

3. **Manual PR creation:**
   ```bash
   # Get commit details
   ca stack
   
   # Create PR manually in Bitbucket UI
   # Then update stack metadata
   ca stacks submit --pr-id 123
   ```

### **🔴 Performance Issues**

#### **Slow operations in large repositories**

**Symptoms:**
- Commands taking > 30 seconds
- High memory usage
- Timeouts

**Solutions:**

1. **Optimize Git configuration:**
   ```bash
   git config core.preloadindex true
   git config core.fscache true
   git config gc.auto 256
   ```

2. **Adjust Cascade CLI settings:**
   ```bash
   ca config set performance.cache_size 500
   ca config set performance.parallel_operations false
   ca config set network.timeout 120
   ```

3. **Repository maintenance:**
   ```bash
   # Clean up Git repository
   git gc --aggressive
   git prune
   
   # Clear Cascade cache
   rm -rf .cascade/cache/
   ```

#### **High memory usage**

**Solutions:**

1. **Reduce cache size:**
   ```bash
   ca config set performance.cache_size 100
   ```

2. **Monitor memory usage:**
   ```bash
   # During operation
   top -p $(pgrep cc)
   
   # Check cache directory size
   du -sh .cascade/cache/
   ```

### **🔴 TUI (Terminal User Interface) Issues**

#### **TUI display problems**

**Symptoms:**
- Garbled characters
- No colors
- Layout issues

**Solutions:**

1. **Check terminal capabilities:**
   ```bash
   echo $TERM
   # Should be xterm-256color or similar
   
   # Test colors
   tput colors
   # Should be 256 or higher
   ```

2. **Fix terminal settings:**
   ```bash
   export TERM=xterm-256color
   
   # For tmux users
   export TERM=screen-256color
   ```

3. **Disable colors if needed:**
   ```bash
   ca config set ui.colors false
   ca tui
   ```

#### **TUI crashes or freezes**

**Solutions:**

1. **Update terminal:**
   ```bash
   # Check for terminal updates
   # Try different terminal: iTerm2, Alacritty, etc.
   ```

2. **Reset TUI settings:**
   ```bash
   ca config unset ui.tui_refresh_rate
   ca config unset ui.tui_theme
   ```

3. **Use alternative interface:**
   ```bash
   # Use CLI instead of TUI
   ca stacks list --verbose
   ca viz stack
   ```

### **🔴 Git Hooks Issues**

#### **Hooks not working**

**Symptoms:**
- Commits not auto-added to stack
- No pre-push validation

**Solutions:**

1. **Check hook installation:**
   ```bash
   ca hooks status
   ls -la .git/hooks/
   ```

2. **Verify permissions:**
   ```bash
   chmod +x .git/hooks/post-commit
   chmod +x .git/hooks/pre-push
   ```

3. **Reinstall hooks:**
   ```bash
   ca hooks uninstall
   ca hooks install --force
   ```

#### **Hook conflicts**

**Symptoms:**
```
Error: Existing hook found, use --force to overwrite
```

**Solutions:**

1. **Backup existing hooks:**
   ```bash
   cp .git/hooks/post-commit .git/hooks/post-commit.backup
   ```

2. **Force install:**
   ```bash
   ca hooks install --force
   ```

3. **Manual integration:**
   ```bash
   # Edit existing hook to call Cascade CLI
   echo "ca stacks push --auto || true" >> .git/hooks/post-commit
   ```

---

## 🔍 **Advanced Debugging**

### **Enable Debug Logging**

```bash
# Set debug level
export CASCADE_LOG_LEVEL=debug

# Run command with debug output
ca stacks push

# Check logs
tail -f ~/.cascade/logs/cascade.log
```

### **Capture System Information**

```bash
# Full diagnostic report
ca doctor --verbose > cascade-debug.txt

# Add system info
echo "=== System Info ===" >> cascade-debug.txt
uname -a >> cascade-debug.txt
git --version >> cascade-debug.txt
rustc --version >> cascade-debug.txt

# Add configuration
echo "=== Configuration ===" >> cascade-debug.txt
ca config list >> cascade-debug.txt

# Add recent logs
echo "=== Recent Logs ===" >> cascade-debug.txt
tail -50 ~/.cascade/logs/cascade.log >> cascade-debug.txt
```

### **Network Debugging**

```bash
# Test Bitbucket API manually
curl -v -H "Authorization: Bearer YOUR_TOKEN" \
     "https://your-bitbucket.com/rest/api/1.0/projects"

# Check DNS resolution
dig your-bitbucket.com

# Test with different timeout
ca config set network.timeout 300
```

### **Repository State Analysis**

```bash
# Check Git integrity
git fsck --full

# Analyze repository size
git count-objects -vH

# Check remote configuration
git remote show origin

# Analyze stack metadata
find .cascade/ -name "*.json" -exec cat {} \;
```

---

## 🛠️ **Recovery Procedures**

### **Complete Reset**

If everything is broken:

```bash
# 1. Backup important work
git stash
git branch backup-$(date +%Y%m%d)

# 2. Remove Cascade configuration
rm -rf .cascade/

# 3. Reinitialize
ca setup

# 4. Recreate stacks manually
ca stacks create recovery --base main
# Cherry-pick commits as needed
```

### **Stack Recovery**

For corrupted stack metadata:

```bash
# 1. Export stack information
ca stack > stack-backup.txt

# 2. Note commit hashes and PR IDs

# 3. Delete corrupted stack
ca stacks delete problematic-stack --force

# 4. Recreate with same commits
ca stacks create recovered-stack --base main
git cherry-pick HASH1
ca stacks push
git cherry-pick HASH2  
ca stacks push

# 5. Reconnect to existing PRs
ca config set stack.recovered-stack.pr.1 PR_ID_1
ca config set stack.recovered-stack.pr.2 PR_ID_2
```

### **Configuration Recovery**

For broken configuration:

```bash
# 1. Backup current config
cp .cascade/config.toml .cascade/config.toml.backup

# 2. Reset to defaults
ca config reset

# 3. Reconfigure step by step
ca config set bitbucket.url "https://your-bitbucket.com"
ca config set bitbucket.project "PROJECT"
ca config set bitbucket.repository "repo"
ca config set bitbucket.token "YOUR_TOKEN"

# 4. Test configuration
ca doctor
```

---

## 📞 **Getting Help**

### **Self-Service Resources**

1. **Built-in help:**
   ```bash
   ca --help
   ca stack --help
   ca stacks create --help
   ```

2. **Diagnostics:**
   ```bash
   ca doctor --verbose
   ```

3. **Documentation:**
   - [User Manual]./USER_MANUAL.md - Complete command reference
   - [Installation Guide]./INSTALLATION.md - Setup instructions
   - [Configuration Guide]./CONFIGURATION.md - Settings reference

### **Community Support**

1. **Search existing issues:**
   - [GitHub Issues]https://github.com/JAManfredi/cascade-cli/issues
   - Use search terms: error message, symptom keywords

2. **Community discussions:**
   - [GitHub Discussions]https://github.com/JAManfredi/cascade-cli/discussions
   - Stack Overflow (tag: cascade-cli)

3. **Create new issue:**
   Include this information:
   ```bash
   # System information
   ca doctor --verbose
   
   # Error reproduction steps
   # Expected vs actual behavior
   # Configuration (sanitized)
   ca config list | sed 's/token = .*/token = [REDACTED]/'
   ```

### **Enterprise Support**

For enterprise users:

1. **Internal support channels:**
   - Check your company's internal documentation
   - Contact IT support for network/proxy issues

2. **Configuration templates:**
   - Ask your team lead for standard configuration
   - Check if there's a company-specific setup guide

---

## 🎯 **Prevention Tips**

### **Best Practices**

1. **Regular maintenance:**
   ```bash
   # Weekly repository cleanup
   git gc
   ca doctor
   
   # Monthly cache cleanup
   rm -rf .cascade/cache/
   ```

2. **Configuration backup:**
   ```bash
   # Backup configuration
   cp .cascade/config.toml ~/.cascade-config-backup.toml
   
   # Version control team config
   git add .cascade/config.toml
   git commit -m "Add team Cascade CLI configuration"
   ```

3. **Monitor health:**
   ```bash
   # Regular health checks
   ca doctor | grep -E "(ERROR|WARN)"
   
   # Check for updates
   cargo install cascade-cli --force
   ```

### **Common Mistakes to Avoid**

1. **Don't manually force push to shared branches** (Cascade CLI handles force pushes safely during rebase)
2. **Don't ignore merge conflicts**  
3. **Don't work on multiple stacks simultaneously without switching**
4. **Don't delete .cascade/ directory unless troubleshooting**
5. **Don't commit sensitive information in configuration**

---

## **Smart Force Push Issues**

### **Force Push Failed**

If force push operations fail during rebase:

```bash
# Error: Force push rejected
# Solution 1: Check branch protection rules
git ls-remote --heads origin | grep your-branch

# Solution 2: Verify you have push permissions
git remote show origin

# Solution 3: Force push manually as fallback
git checkout original-branch
git reset --hard versioned-branch
git push --force-with-lease origin original-branch
```

### **PR Links Broken After Rebase**

If PRs don't update correctly:

```bash
# Check if PRs still exist
ca stacks prs --verbose

# Manually update PR if needed  
ca config set stack.STACK_NAME.pr.INDEX PR_ID

# Re-submit if PR was closed
ca stacks submit INDEX --title "Updated after rebase"
```

### **Temporary Branches Accumulating**

If a rebase operation is interrupted, temporary branches may be left behind:

```bash
# Check for orphaned temp branches (dry-run)
ca cleanup

# Actually delete them
ca cleanup --execute

# Force delete even if they have unmerged commits
ca cleanup --execute --force

# Or manually list and delete
git branch | grep -E '.*-temp-[0-9]+$'
git branch -D branch-temp-1234567890
```

**Why this happens**: During rebase, Cascade creates temporary branches with 
timestamps (e.g., `feature-temp-1234567890`). These are normally cleaned up 
automatically, but may remain if the process is killed or errors occur.

### **Force Push Safety Concerns**

Understanding when force pushes are safe:

```bash
# Cascade CLI force pushes are safe because:
# 1. Only affects your feature branches (never main/develop)
# 2. Validates existing PRs before pushing
# 3. Creates backup branches before operations
# 4. Uses --force-with-lease for additional safety

# Check backup branches exist
git branch | grep -E '.*-v[0-9]+$'

# Manually verify safety
git log --oneline origin/your-branch..your-branch-v2
```

---

## 📊 **Error Code Reference**

| Code | Meaning | Common Solutions |
|------|---------|------------------|
| E001 | Configuration missing | Run `ca init` or `ca setup` |
| E002 | Git repository not found | Ensure you're in a Git repository |
| E003 | Bitbucket connection failed | Check credentials and network |
| E004 | Stack not found | Use `ca stacks list` to see available stacks |
| E005 | Merge conflict detected | Resolve conflicts and run `ca rebase continue` or `ca sync continue` |
| E006 | Invalid commit hash | Check commit exists with `git log` |
| E007 | Permission denied | Check file permissions and access rights |
| E008 | Network timeout | Increase timeout with `ca config set network.timeout 120` |

---

*If your issue isn't covered here, please [create an issue](https://github.com/JAManfredi/cascade-cli/issues/new) with detailed information about your problem.*