Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"Bash(./target/debug/git-x stash-branch --help)",
"Bash(timeout 15 cargo test --test test_interactive)",
"Bash(timeout 30 cargo test --test test_interactive -- --test-threads=1)",
"Bash(timeout 20 cargo test --test test_interactive -- --test-threads=1)"
"Bash(timeout 20 cargo test --test test_interactive -- --test-threads=1)",
"Bash(GIT_X_NON_INTERACTIVE=1 cargo test test_health_command_direct -- --nocapture)",
"Bash(git x:*)"
],
"deny": []
}
Expand Down
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ chrono = "0.4"
dialoguer = { version = "0.11", features = ["fuzzy-select"] }
fuzzy-matcher = "0.3"
atty = "0.2"
indicatif = "0.17"

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
72 changes: 69 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,49 @@ git x health
```shell
🏥 Repository Health Check
==============================
⠁ [00:00:01] [########################################] 8/8 Health check complete!
✅ Git configuration: OK
✅ Remotes: OK
✅ Branches: OK
✅ Working directory: Clean
✅ Repository size: OK
⚠️ Security: Potential issues found
✅ .gitignore: Looks good
✅ Binary files: OK

🎉 Repository is healthy!
🔧 Found 3 issue(s):
🔒 2 potentially sensitive commit message(s) found:
• a1b2c3d Add API key configuration
• d4e5f6g Update secret token handling
🔐 1 potentially sensitive file(s) in repository:
• config/private.key
⚠️ 2 environment file(s) found - ensure no secrets are committed:
• .env.local
• .env.production
```

#### What it checks:
- **Git configuration** - Validates user.name and user.email settings
- **Remotes** - Ensures remote repositories are configured
- **Working directory status** - Detects uncommitted changes
- **Untracked files** - Counts files not under version control
- **Stale branches** - Identifies branches older than 1 month
- **Repository size** - Warns about large repositories that may need cleanup
- **Staged changes** - Shows files ready for commit
- **Security issues** - Scans for potential credentials in history and sensitive files
- **.gitignore effectiveness** - Suggests improvements to ignore patterns
- **Binary files** - Identifies large binary files that might benefit from Git LFS

#### Enhanced Features:
- **Progress Indicator**: Real-time progress bar showing current check being performed
- **Detailed Security Reporting**: Shows exactly which commits, files, and patterns triggered security warnings
- **Specific Recommendations**: Lists actual files and examples instead of just counts
- **Performance Optimized**: Efficiently scans large repositories with visual feedback

Useful for:
- Daily repository maintenance
- Pre-commit health checks
- Security auditing
- Identifying cleanup opportunities
- Team onboarding (ensuring clean local state)

Expand All @@ -312,8 +336,21 @@ git x info
✅ Status: Up to date
⚠️ Working directory: Has changes
📋 Staged files: None
❌ No open PR for current branch
📊 vs main: 2 ahead, 1 behind

📋 Recent activity:
* a1b2c3d Add new feature (2 hours ago) <Alice>
* d4e5f6g Fix bug in parser (4 hours ago) <Bob>
* g7h8i9j Update documentation (1 day ago) <Charlie>
```

#### Enhanced Features:
- **Recent activity timeline** - Shows recent commits across all branches with author info
- **GitHub PR detection** - Automatically detects if current branch has an open pull request (requires `gh` CLI)
- **Branch comparisons** - Shows ahead/behind status compared to main branches
- **Detailed view** - Use any git-x command to see additional details

---

### `large-files`
Expand Down Expand Up @@ -453,6 +490,8 @@ git x since origin/main
git x stash-branch create new-feature
git x stash-branch clean --older-than 7d
git x stash-branch apply-by-branch feature-work
git x stash-branch interactive
git x stash-branch export ./patches
```

#### Subcommands:
Expand Down Expand Up @@ -482,9 +521,36 @@ This will delete 3 stashes: stash@{0}, stash@{1}, stash@{2}
**`apply-by-branch <branch-name>`** — Apply stashes from a specific branch
- `--list` — List matching stashes instead of applying

Helps manage stashes more effectively by associating them with branches.
**`interactive`** — Interactive stash management with fuzzy search
- Visual menu for applying, deleting, or creating branches from stashes
- Supports multiple selection for batch operations
- Shows stash content and branch associations

**`export <output-dir>`** — Export stashes to patch files
- `--stash <ref>` — Export specific stash (default: all stashes)
- Creates `.patch` files that can be shared or archived
- Useful for backing up or sharing stash content

#### Example Output for `interactive`:

```shell
📋 What would you like to do?
❯ Apply selected stash
Delete selected stashes
Create branch from stash
Show stash diff
List all stashes
Exit

🎯 Select stash to apply:
❯ stash@{0}: WIP on feature: Add authentication (from feature-auth)
stash@{1}: On main: Fix README typo (from main)
stash@{2}: WIP on bugfix: Debug API calls (from api-fixes)
```

Helps manage stashes more effectively by associating them with branches and providing modern interactive workflows.

**Note:** The `clean` command will prompt for confirmation before deleting stashes to prevent accidental data loss.
**Note:** Interactive and destructive commands will prompt for confirmation to prevent accidental data loss.

---

Expand Down
49 changes: 43 additions & 6 deletions docs/command-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ This document explains how each `git-x` subcommand works under the hood. We aim
## `info`

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

### Under the hood:
- `git rev-parse --show-toplevel` → Get the repo root.
**Basic repository info:**
- `git rev-parse --show-toplevel` → Get the repo root and repository name.
- `git rev-parse --abbrev-ref HEAD` → Get current branch name.
- `git for-each-ref --format='%(upstream:short)'` → Find tracking branch.
- `git rev-list --left-right --count HEAD...@{upstream}` → Ahead/behind counts.
- `git log -1 --pretty=format:"%s (%cr)"` → Most recent commit summary.
- `git rev-list --left-right --count HEAD...@{upstream}` → Ahead/behind counts with upstream.
- `git diff --cached --name-only` → List staged files.
- `git status --porcelain` → Check working directory cleanliness.

**Enhanced features:**
- `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.
- `gh pr status --json currentBranch` → GitHub PR detection (if `gh` CLI available).
- `git rev-list --left-right --count main...HEAD` → Branch differences against main/master/develop branches.
- `git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)'` → Recent branches list (detailed mode).

---

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

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

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

**Security checks with detailed reporting:**
- `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
- `git ls-files *.pem *.key *.p12 *.pfx *.jks` → Find potentially sensitive files and list specific filenames
- `git ls-files *.env*` → Find environment files that might contain secrets and show which files

**Repository optimization checks:**
- `git ls-files .gitignore` → Verify .gitignore exists
- `git ls-files *.log *.tmp *.swp *.bak .DS_Store Thumbs.db node_modules/ target/ .vscode/ .idea/` → Check for files that should be ignored
- Binary file detection using `git diff --no-index /dev/null <file> --numstat` → Identify large binary files with sizes and Git LFS recommendations
- Progress tracking using `indicatif` crate → Real-time progress bar showing current check being performed

---

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

**`interactive` subcommand:**
- `git stash list --pretty=format:'%gd|%s'` → Get stash list for interactive menu
- Uses `dialoguer` crate for interactive TUI with fuzzy selection
- Supports multiple actions: apply, delete, create branch, show diff, list
- `git stash apply/drop/branch/show -p <stash-ref>` → Execute selected action
- Multi-select for batch operations (delete multiple stashes)

**`export` subcommand:**
- `git stash list --pretty=format:'%gd|%s'` → Get list of stashes to export
- `git stash show -p <stash-ref>` → Generate patch content for each stash
- Creates `.patch` files in specified output directory
- Sanitizes stash names for safe filenames (removes special characters)
- Supports exporting all stashes or a specific stash reference

---

## `upstream`
Expand Down
12 changes: 12 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ pub enum StashBranchAction {
#[clap(long = "list", help = "List stashes instead of applying", action = clap::ArgAction::SetTrue)]
list_only: bool,
},
#[clap(about = "Interactive stash management with fuzzy search")]
Interactive,
#[clap(about = "Export stashes to patch files")]
Export {
#[clap(help = "Output directory for patch files")]
output_dir: String,
#[clap(
long = "stash",
help = "Specific stash to export (default: all stashes)"
)]
stash_ref: Option<String>,
},
}

#[derive(clap::Subcommand)]
Expand Down
Loading
Loading