Skip to content

Commit bcfca30

Browse files
committed
Extend health, info and stash commands
1 parent 8f801df commit bcfca30

19 files changed

+1213
-71
lines changed

.claude/settings.local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"Bash(./target/debug/git-x stash-branch --help)",
4242
"Bash(timeout 15 cargo test --test test_interactive)",
4343
"Bash(timeout 30 cargo test --test test_interactive -- --test-threads=1)",
44-
"Bash(timeout 20 cargo test --test test_interactive -- --test-threads=1)"
44+
"Bash(timeout 20 cargo test --test test_interactive -- --test-threads=1)",
45+
"Bash(GIT_X_NON_INTERACTIVE=1 cargo test test_health_command_direct -- --nocapture)",
46+
"Bash(git x:*)"
4547
],
4648
"deny": []
4749
}

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ chrono = "0.4"
2929
dialoguer = { version = "0.11", features = ["fuzzy-select"] }
3030
fuzzy-matcher = "0.3"
3131
atty = "0.2"
32+
indicatif = "0.17"
3233

3334
[dev-dependencies]
3435
assert_cmd = "2.0"

README.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,25 +271,49 @@ git x health
271271
```shell
272272
🏥 Repository Health Check
273273
==============================
274+
⠁ [00:00:01] [########################################] 8/8 Health check complete!
274275
✅ Git configuration: OK
275276
✅ Remotes: OK
276277
✅ Branches: OK
277278
✅ Working directory: Clean
278279
✅ Repository size: OK
280+
⚠️ Security: Potential issues found
281+
✅ .gitignore: Looks good
282+
✅ Binary files: OK
279283
280-
🎉 Repository is healthy!
284+
🔧 Found 3 issue(s):
285+
🔒 2 potentially sensitive commit message(s) found:
286+
• a1b2c3d Add API key configuration
287+
• d4e5f6g Update secret token handling
288+
🔐 1 potentially sensitive file(s) in repository:
289+
• config/private.key
290+
⚠️ 2 environment file(s) found - ensure no secrets are committed:
291+
• .env.local
292+
• .env.production
281293
```
282294
283295
#### What it checks:
296+
- **Git configuration** - Validates user.name and user.email settings
297+
- **Remotes** - Ensures remote repositories are configured
284298
- **Working directory status** - Detects uncommitted changes
285299
- **Untracked files** - Counts files not under version control
286300
- **Stale branches** - Identifies branches older than 1 month
287301
- **Repository size** - Warns about large repositories that may need cleanup
288302
- **Staged changes** - Shows files ready for commit
303+
- **Security issues** - Scans for potential credentials in history and sensitive files
304+
- **.gitignore effectiveness** - Suggests improvements to ignore patterns
305+
- **Binary files** - Identifies large binary files that might benefit from Git LFS
306+
307+
#### Enhanced Features:
308+
- **Progress Indicator**: Real-time progress bar showing current check being performed
309+
- **Detailed Security Reporting**: Shows exactly which commits, files, and patterns triggered security warnings
310+
- **Specific Recommendations**: Lists actual files and examples instead of just counts
311+
- **Performance Optimized**: Efficiently scans large repositories with visual feedback
289312
290313
Useful for:
291314
- Daily repository maintenance
292315
- Pre-commit health checks
316+
- Security auditing
293317
- Identifying cleanup opportunities
294318
- Team onboarding (ensuring clean local state)
295319
@@ -312,8 +336,21 @@ git x info
312336
✅ Status: Up to date
313337
⚠️ Working directory: Has changes
314338
📋 Staged files: None
339+
❌ No open PR for current branch
340+
📊 vs main: 2 ahead, 1 behind
341+
342+
📋 Recent activity:
343+
* a1b2c3d Add new feature (2 hours ago) <Alice>
344+
* d4e5f6g Fix bug in parser (4 hours ago) <Bob>
345+
* g7h8i9j Update documentation (1 day ago) <Charlie>
315346
```
316347
348+
#### Enhanced Features:
349+
- **Recent activity timeline** - Shows recent commits across all branches with author info
350+
- **GitHub PR detection** - Automatically detects if current branch has an open pull request (requires `gh` CLI)
351+
- **Branch comparisons** - Shows ahead/behind status compared to main branches
352+
- **Detailed view** - Use any git-x command to see additional details
353+
317354
---
318355
319356
### `large-files`
@@ -453,6 +490,8 @@ git x since origin/main
453490
git x stash-branch create new-feature
454491
git x stash-branch clean --older-than 7d
455492
git x stash-branch apply-by-branch feature-work
493+
git x stash-branch interactive
494+
git x stash-branch export ./patches
456495
```
457496
458497
#### Subcommands:
@@ -482,9 +521,36 @@ This will delete 3 stashes: stash@{0}, stash@{1}, stash@{2}
482521
**`apply-by-branch <branch-name>`** — Apply stashes from a specific branch
483522
- `--list` — List matching stashes instead of applying
484523
485-
Helps manage stashes more effectively by associating them with branches.
524+
**`interactive`** — Interactive stash management with fuzzy search
525+
- Visual menu for applying, deleting, or creating branches from stashes
526+
- Supports multiple selection for batch operations
527+
- Shows stash content and branch associations
528+
529+
**`export <output-dir>`** — Export stashes to patch files
530+
- `--stash <ref>` — Export specific stash (default: all stashes)
531+
- Creates `.patch` files that can be shared or archived
532+
- Useful for backing up or sharing stash content
533+
534+
#### Example Output for `interactive`:
535+
536+
```shell
537+
📋 What would you like to do?
538+
❯ Apply selected stash
539+
Delete selected stashes
540+
Create branch from stash
541+
Show stash diff
542+
List all stashes
543+
Exit
544+
545+
🎯 Select stash to apply:
546+
❯ stash@{0}: WIP on feature: Add authentication (from feature-auth)
547+
stash@{1}: On main: Fix README typo (from main)
548+
stash@{2}: WIP on bugfix: Debug API calls (from api-fixes)
549+
```
550+
551+
Helps manage stashes more effectively by associating them with branches and providing modern interactive workflows.
486552
487-
**Note:** The `clean` command will prompt for confirmation before deleting stashes to prevent accidental data loss.
553+
**Note:** Interactive and destructive commands will prompt for confirmation to prevent accidental data loss.
488554
489555
---
490556

docs/command-internals.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,22 @@ This document explains how each `git-x` subcommand works under the hood. We aim
4848
## `info`
4949

5050
### What it does:
51-
- Displays a high-level overview of the current repository.
51+
- Displays a comprehensive overview of the current repository including recent activity, branch comparisons, and PR status.
5252

5353
### Under the hood:
54-
- `git rev-parse --show-toplevel` → Get the repo root.
54+
**Basic repository info:**
55+
- `git rev-parse --show-toplevel` → Get the repo root and repository name.
5556
- `git rev-parse --abbrev-ref HEAD` → Get current branch name.
5657
- `git for-each-ref --format='%(upstream:short)'` → Find tracking branch.
57-
- `git rev-list --left-right --count HEAD...@{upstream}` → Ahead/behind counts.
58-
- `git log -1 --pretty=format:"%s (%cr)"` → Most recent commit summary.
58+
- `git rev-list --left-right --count HEAD...@{upstream}` → Ahead/behind counts with upstream.
59+
- `git diff --cached --name-only` → List staged files.
60+
- `git status --porcelain` → Check working directory cleanliness.
61+
62+
**Enhanced features:**
63+
- `git log --oneline --decorate --graph --all --max-count=8 --pretty=format:'%C(auto)%h %s %C(dim)(%cr) %C(bold blue)<%an>%C(reset)'` → Recent activity timeline with author info.
64+
- `gh pr status --json currentBranch` → GitHub PR detection (if `gh` CLI available).
65+
- `git rev-list --left-right --count main...HEAD` → Branch differences against main/master/develop branches.
66+
- `git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)'` → Recent branches list (detailed mode).
5967

6068
---
6169

@@ -112,16 +120,31 @@ This document explains how each `git-x` subcommand works under the hood. We aim
112120
## `health`
113121

114122
### What it does:
115-
- Performs a comprehensive repository health check to identify potential issues and maintenance needs.
123+
- Performs a comprehensive repository health check with real-time progress indicators and detailed security reporting.
116124

117125
### Under the hood:
126+
**Core health checks:**
118127
- `git rev-parse --git-dir` → Verify we're in a Git repository
128+
- `git config user.name` → Check Git user configuration
129+
- `git config user.email` → Check Git email configuration
130+
- `git remote` → Verify remote repositories are configured
119131
- `git status --porcelain` → Check working directory status
120132
- `git ls-files --others --exclude-standard` → Count untracked files
121133
- `git for-each-ref --format='%(refname:short) %(committerdate:relative)' refs/heads/` → Identify stale branches
122-
- `du -sh .git` → Check repository size
134+
- `git count-objects -vH` → Check repository size with human-readable output
123135
- `git diff --cached --name-only` → Check for staged changes
124136

137+
**Security checks with detailed reporting:**
138+
- `git log --all --full-history --grep=password --grep=secret --grep=key --grep=token --grep=credential --pretty=format:'%h %s' -i` → Scan for potential credentials in commit messages with commit hashes and messages
139+
- `git ls-files *.pem *.key *.p12 *.pfx *.jks` → Find potentially sensitive files and list specific filenames
140+
- `git ls-files *.env*` → Find environment files that might contain secrets and show which files
141+
142+
**Repository optimization checks:**
143+
- `git ls-files .gitignore` → Verify .gitignore exists
144+
- `git ls-files *.log *.tmp *.swp *.bak .DS_Store Thumbs.db node_modules/ target/ .vscode/ .idea/` → Check for files that should be ignored
145+
- Binary file detection using `git diff --no-index /dev/null <file> --numstat` → Identify large binary files with sizes and Git LFS recommendations
146+
- Progress tracking using `indicatif` crate → Real-time progress bar showing current check being performed
147+
125148
---
126149

127150
## `technical-debt`
@@ -334,6 +357,20 @@ This document explains how each `git-x` subcommand works under the hood. We aim
334357
- Filters stashes by branch name pattern
335358
- `git stash apply <stash-ref>` → Apply matching stashes
336359

360+
**`interactive` subcommand:**
361+
- `git stash list --pretty=format:'%gd|%s'` → Get stash list for interactive menu
362+
- Uses `dialoguer` crate for interactive TUI with fuzzy selection
363+
- Supports multiple actions: apply, delete, create branch, show diff, list
364+
- `git stash apply/drop/branch/show -p <stash-ref>` → Execute selected action
365+
- Multi-select for batch operations (delete multiple stashes)
366+
367+
**`export` subcommand:**
368+
- `git stash list --pretty=format:'%gd|%s'` → Get list of stashes to export
369+
- `git stash show -p <stash-ref>` → Generate patch content for each stash
370+
- Creates `.patch` files in specified output directory
371+
- Sanitizes stash names for safe filenames (removes special characters)
372+
- Supports exporting all stashes or a specific stash reference
373+
337374
---
338375

339376
## `upstream`

src/cli.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ pub enum StashBranchAction {
138138
#[clap(long = "list", help = "List stashes instead of applying", action = clap::ArgAction::SetTrue)]
139139
list_only: bool,
140140
},
141+
#[clap(about = "Interactive stash management with fuzzy search")]
142+
Interactive,
143+
#[clap(about = "Export stashes to patch files")]
144+
Export {
145+
#[clap(help = "Output directory for patch files")]
146+
output_dir: String,
147+
#[clap(
148+
long = "stash",
149+
help = "Specific stash to export (default: all stashes)"
150+
)]
151+
stash_ref: Option<String>,
152+
},
141153
}
142154

143155
#[derive(clap::Subcommand)]

0 commit comments

Comments
 (0)