git-alias 1.2.29

A fast git alias tool with dual-style command support
# Makefile for git-alias
# Works on Windows Git Bash / MSYS2, macOS, and Linux

.PHONY: all build release install install-debug test test-cmd run clean fmt lint check help

# ------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------

CARGO := cargo
CARGO_FLAGS ?=
RELEASE_DIR := target/release
DEBUG_DIR := target/debug
BIN_NAME := git-alias

# Windows extension detection (must happen before BIN is defined)
ifdef OS
  ifeq ($(OS),Windows_NT)
    EXEEXT := .exe
  endif
endif

BIN := $(RELEASE_DIR)/$(BIN_NAME)$(EXEEXT)
DEBUG_BIN := $(DEBUG_DIR)/$(BIN_NAME)$(EXEEXT)

# Install directory (mirrors src/main.rs install_all logic)
HOME_DIR := $(shell echo $$HOME)
INSTALL_DIR := $(HOME_DIR)/.local/bin

# Detect shell for completions
SHELL_NAME := $(notdir $(SHELL))

# ------------------------------------------------------------------
# Default target
# ------------------------------------------------------------------

all: release

# ------------------------------------------------------------------
# Build targets
# ------------------------------------------------------------------

build: ## Build debug binary
	$(CARGO) build $(CARGO_FLAGS)

release: ## Build optimized release binary
	$(CARGO) build --release $(CARGO_FLAGS)

run: build ## Build and run with `g stat` on current repo
	$(DEBUG_BIN) stat

# ------------------------------------------------------------------
# Install / uninstall
# ------------------------------------------------------------------

install: release ## Install release binary and all aliases to ~/.local/bin
	@mkdir -p $(INSTALL_DIR)
	cp $(BIN) $(INSTALL_DIR)/g$(EXEEXT)
	@echo "Installed: $(INSTALL_DIR)/g$(EXEEXT)"
	$(BIN) install

install-debug: build ## Install debug binary and all aliases to ~/.local/bin
	@mkdir -p $(INSTALL_DIR)
	cp $(DEBUG_BIN) $(INSTALL_DIR)/g$(EXEEXT)
	@echo "Installed (debug): $(INSTALL_DIR)/g$(EXEEXT)"
	$(DEBUG_BIN) install

uninstall: ## Remove installed binaries from ~/.local/bin
	@echo "Removing installed binaries from $(INSTALL_DIR) ..."
	@rm -f $(INSTALL_DIR)/g$(EXEEXT)
	@$(CARGO) run --quiet -- install 2>/dev/null || true
	@echo "Done. Note: this leaves shell wrappers; run 'rm -f $(INSTALL_DIR)/g*' manually if needed."

# ------------------------------------------------------------------
# Development helpers
# ------------------------------------------------------------------

test: ## Run unit tests and doc tests
	$(CARGO) test $(CARGO_FLAGS)

test-cmd: release ## Run g stat integration tests on current repo
	@echo "==> g stat"
	$(BIN) stat
	@echo
	@echo "==> g stat --month"
	$(BIN) stat --month
	@echo
	@echo "==> g stat --help"
	$(BIN) stat --help
	@echo
	@echo "==> g stat --today --week (should error)"
	$(BIN) stat --today --week || true

fmt: ## Format all Rust source files
	$(CARGO) fmt

lint: ## Run Clippy lints
	$(CARGO) clippy --all-targets --all-features -- -D warnings

check: ## Fast syntax/type check without codegen
	$(CARGO) check $(CARGO_FLAGS)

# ------------------------------------------------------------------
# Completions (local one-off)
# ------------------------------------------------------------------

completions: release ## Generate shell completions for current shell
	$(BIN) completions $(SHELL_NAME)

# ------------------------------------------------------------------
# Cleaning
# ------------------------------------------------------------------

clean: ## Remove build artifacts
	$(CARGO) clean
	@rm -f Cargo.lock.orig

# ------------------------------------------------------------------
# Release packaging
# ------------------------------------------------------------------

package: release ## Package release binary for current platform
	@mkdir -p dist
	cp $(BIN) dist/git-alias-$(shell $(BIN) --version | awk '{print $$2}')-$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(shell uname -m)$(EXEEXT)
	@echo "Packaged: dist/"

# ------------------------------------------------------------------
# Help
# ------------------------------------------------------------------

help: ## Show this help message
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help