hmm-git-safety
Version:
A safety wrapper for git push that prevents accidental pushes to origin without branch name
175 lines (137 loc) • 3.54 kB
Markdown
# Quick Start Guide for hmm
## For End Users
### Install using NPM (if you have Node.js)
```bash
npm install -g hmm-git-safety
# hmm is now installed and active after restarting terminal
```
### Install using pip (if you have Python)
```bash
pip install hmm-git-safety
# hmm is now installed and active after restarting terminal
```
### Install using the GUI (easiest for non-technical users)
```bash
# Download the project and run:
python3 gui_installer.py
```
### Install using the shell script (works everywhere)
```bash
# Download and run:
curl -fsSL https://raw.githubusercontent.com/yourusername/hmm/main/install.sh | bash
# Then restart your terminal or run: source ~/.zshrc
```
## Testing hmm
After installation and restarting your terminal:
```bash
# This will work normally
git push origin main
# This will trigger 3 confirmations
git push origin
```
## Uninstalling
```bash
# Using the command
hmm uninstall
# Or reinstall and use the GUI
python3 gui_installer.py
```
## For Developers / Package Maintainers
### Publishing to NPM
```bash
# Login to npm
npm login
# Publish package
npm publish
```
### Publishing to PyPI
```bash
# Install build tools
pip install build twine
# Build the package
python -m build
# Upload to PyPI
python -m twine upload dist/*
```
### Creating Homebrew Formula
```bash
# 1. Create a GitHub release with a tarball
# 2. Get the SHA256 of the tarball
shasum -a 256 hmm-1.0.0.tar.gz
# 3. Update hmm.rb with the correct URL and SHA256
# 4. Submit to homebrew-core or create your own tap
```
### Testing Locally
#### Test NPM Package
```bash
# In the hmm directory
npm link
hmm install
hmm status
```
#### Test Python Package
```bash
# In the hmm directory
pip install -e .
hmm install
hmm status
```
#### Test Shell Scripts
```bash
chmod +x install.sh uninstall.sh
./install.sh
source ~/.zshrc
# Test git push origin
./uninstall.sh
```
#### Test GUI
```bash
python3 gui_installer.py
# Use the GUI to install/uninstall
```
## Troubleshooting
### hmm not working after install
- Make sure you restarted your terminal or ran `source ~/.zshrc` (or `~/.bashrc`)
- Run `hmm status` to check if it's installed
- Check that the function is loaded: `type git`
### Permission errors
- Make sure scripts are executable: `chmod +x install.sh uninstall.sh`
- Run with appropriate permissions or use sudo if needed
### Wrong shell config file
- hmm auto-detects your shell, but you can manually add to the correct config file
- Check what shell youre using: `echo $SHELL`
- Manually edit the appropriate config file if needed
## Advanced Usage
### Manual Installation
Add this to your `~/.zshrc` or `~/.bashrc`:
```bash
git() {
if [[ "$1" == "push" && "$2" == "origin" && -z "$3" ]]; then
RED='\033[0;31m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
WARNINGS=(
"${RED} DANGER: You are pushing to ORIGIN without a branch!${NC}"
"${YELLOW} WARNING: This may overwrite or break things on origin!${NC}"
"${CYAN} FINAL CHECK: Do you really want to do this?${NC}"
)
for i in {1..3}; do
echo -e "${WARNINGS[$i]}"
echo -n "Type 'yes' to confirm [$i/3]: "
read answer
if [[ "$answer" != "yes" ]]; then
echo "Push cancelled."
return 1
fi
done
fi
command git "$@"
}
```
### Customization
You can modify the wrapper function to:
- Change the number of confirmations
- Customize warning messages
- Add additional git command protections
- Integrate with your team's workflow