Skip to content
Open
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
131 changes: 131 additions & 0 deletions CHANGELOG_GITHUB_DESKTOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Changelog: GitHub Desktop Support

## Summary

Added support for GitHub Desktop and other Git clients by implementing pre-commit hook installation alongside the existing pre-push hook functionality.

## Problem

GitHub Desktop does not execute pre-push hooks, making the original `bark git-hook install` command ineffective for GitHub Desktop users. Users could commit and push code with BARK comments without any warnings.

## Solution

Implemented new commands to install/uninstall pre-commit hooks, which GitHub Desktop does respect.

## Changes Made

### 1. Code Changes (`cmd/bark/main.go`)

#### New Commands
- `bark git-hook install-commit` - Install pre-commit hook
- `bark git-hook uninstall-commit` - Uninstall pre-commit hook

#### New Constants
- `hookContentCommit` - Pre-commit hook script template (similar to pre-push but with different messaging)

#### New Functions
- `installGitHookCommit()` - Installs bark as a pre-commit hook
- `uninstallGitHookCommit()` - Removes bark pre-commit hook

#### Updated Help Text
- Added new commands to usage documentation
- Updated examples to show both hook types

### 2. Documentation Updates

#### Updated `README.md`
- **Features section**: Updated to mention both pre-commit and pre-push hooks with GitHub Desktop support
- **Installation section**: Split into two subsections:
- "For GitHub Desktop Users (Pre-Commit Hook)"
- "For CLI Git Users (Pre-Push Hook)"
- **Added explanation**: Why two options exist and when to use each
- **Git Hook Commands section**: Completely restructured to show both hook types with clear examples

#### New `GITHUB_DESKTOP.md`
- Comprehensive guide for GitHub Desktop users
- Explains the problem and solution
- Step-by-step installation instructions
- Troubleshooting section
- Examples of how it works in practice

### 3. Behavior

#### Pre-Commit Hook (`install-commit`)
- Runs before each commit
- Blocks commits if BARK comments are found
- Works with: GitHub Desktop, VS Code, CLI git, and all other Git clients
- Message: "❌ Commit blocked: BARK comments found"

#### Pre-Push Hook (`install`)
- Runs before each push
- Blocks pushes if BARK comments are found
- Works with: CLI git only (bypassed by GitHub Desktop)
- Message: "❌ Push blocked: BARK comments found"

#### Both Hooks Can Coexist
- Users can install both hooks simultaneously
- Provides double protection
- Each hook uses the same marker system (`# BEGIN bark hook` / `# END bark hook`)

## Testing

Tested in Demo-inator repository:
- ✅ Pre-commit hook installed successfully
- ✅ Pre-push hook installed successfully
- ✅ Both hooks coexist in `.git/hooks/` directory
- ✅ Pre-commit hook detects BARK comments
- ✅ Proper error messages displayed

## Backward Compatibility

This change is **100% backward compatible**:
- Existing `bark git-hook install` command works exactly as before
- Existing `bark git-hook uninstall` command unchanged
- No breaking changes to existing functionality
- New commands are purely additive

## Files Modified

1. `cmd/bark/main.go` - Added new commands and functions
2. `README.md` - Updated documentation
3. `GITHUB_DESKTOP.md` - New file (comprehensive guide)

## Migration Guide

### For Existing Users

No action required! Your existing pre-push hooks continue to work.

### For GitHub Desktop Users

Run this command in your repository:

```bash
bark git-hook install-commit
```

You can keep your existing pre-push hook or remove it:

```bash
# Optional: remove pre-push hook if you only use GitHub Desktop
bark git-hook uninstall
```

## Future Considerations

### Potential Enhancements
1. Add `--all` flag to install both hooks at once: `bark git-hook install --all`
2. Auto-detect Git client and suggest appropriate hook
3. Add configuration file support for default hook type
4. Create pre-commit framework integration

### Known Limitations
1. Users must have `bark` in their PATH for hooks to work
2. GitHub Desktop's environment may differ from terminal (rare edge cases)
3. No automatic hook detection - users must choose which to install

## References

- [GitHub Desktop Issue #13112](https://github.com/desktop/desktop/issues/13112) - Git hook support discussion
- [GitHub Community Discussion #24072](https://github.com/orgs/community/discussions/24072) - Pre-commit hooks on Mac
- [Git Hooks Documentation](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
130 changes: 130 additions & 0 deletions GITHUB_DESKTOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Using Bark with GitHub Desktop

GitHub Desktop is a popular Git client, but it has historically had issues with git hooks. This guide explains how to use Bark effectively with GitHub Desktop.

## The Problem

GitHub Desktop **does not run pre-push hooks** by default. This means the standard `bark git-hook install` command won't work with GitHub Desktop - you'll be able to push code with BARK comments without any warnings.

## The Solution: Pre-Commit Hooks

**Good news!** GitHub Desktop **does support pre-commit hooks**. We've added a new command to Bark that installs a pre-commit hook instead of a pre-push hook.

### Installation

```bash
# Install bark
go install github.com/debkanchan/bark/cmd/bark@latest

# Install the pre-commit hook (works with GitHub Desktop!)
cd /path/to/your/repo
bark git-hook install-commit
```

### How It Works

With the pre-commit hook installed:

1. You add BARK comments to your code as reminders
2. When you try to commit in GitHub Desktop, Bark runs automatically
3. If BARK comments are found, the commit is **blocked**
4. You'll see an error message in GitHub Desktop showing where the BARK comments are
5. Remove the BARK comments and try again

### Example

Let's say you have this code with BARK comments:

```typescript
// BARK: Remove this debug code
console.log("Debug mode enabled");

// BARK: Replace with production API key
const apiKey = "test-123";
```

When you try to commit in GitHub Desktop:

```
🐕 Running bark to check for BARK comments...
Found 2 BARK comment(s):

src/components/Backgrounds.tsx:11:1: // BARK: Remove this debug code
src/components/Backgrounds.tsx:14:1: // BARK: Replace with production API key

❌ Commit blocked: BARK comments found
Please remove BARK comments before committing
Run 'bark .' to see all BARK comments
```

The commit will be rejected! GitHub Desktop will show this error in the commit panel.

## Uninstalling

If you want to remove the pre-commit hook:

```bash
bark git-hook uninstall-commit
```

## Can I Use Both Pre-Commit and Pre-Push?

Yes! You can install both hooks for double protection:

```bash
# Install pre-commit (for GitHub Desktop and early catching)
bark git-hook install-commit

# Install pre-push (for CLI git users as backup)
bark git-hook install
```

## Troubleshooting

### The hook isn't running

1. Make sure you're in the repository root when installing
2. Check that `.git/hooks/pre-commit` exists and is executable:
```bash
ls -la .git/hooks/pre-commit
```
3. Verify bark is in your PATH:
```bash
which bark
# Should show: /Users/yourusername/go/bin/bark
```

### GitHub Desktop shows "hook failed" with no details

This usually means `bark` isn't in GitHub Desktop's PATH. Try:

1. Make sure bark is installed: `which bark`
2. Add Go's bin directory to your PATH in `~/.zshrc` or `~/.bash_profile`:
```bash
export PATH="$HOME/go/bin:$PATH"
```
3. Restart GitHub Desktop

### I want to commit anyway (override the hook)

If you absolutely need to bypass the hook temporarily:

```bash
git commit --no-verify -m "your message"
```

**Warning:** This defeats the purpose of Bark. Only use this if you really know what you're doing!

## Why This Approach?

We chose to create a separate `install-commit` command instead of making `install` automatically detect GitHub Desktop because:

1. **User choice**: Some developers prefer catching BARK comments at push time (allows WIP commits)
2. **Explicit behavior**: It's clearer what each command does
3. **Compatibility**: You can install both hooks if needed

## Resources

- [GitHub Desktop Documentation](https://docs.github.com/en/desktop)
- [Git Hooks Documentation](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
- [Bark Main README](README.md)
Loading