How svedrin/hgit works
Project type and purpose
• This is an open‑source, opinionated CLI tool (“hgit”) written as shell scripts that wrap Git commands and add GitHub‑aware behaviors.
• It provides a simplified “porcelain” interface to common Git workflows (clone, status, diff, commit, branch, push, PR, etc.), plus bash completion, a small config file, and a test harness.
File‑structure analysis
• Top‑level:
– .drone.yml: CI configuration for running tests on pushes
– README.md: full user guide and architecture notes
– hgit.sh: main shell script implementing all “h” subcommands
– hgit_completion.sh: bash completion definitions for the “h” command
– tests.sh: test runner script
• tests/ directory:
– tests/README.md: description of test cases
– individual .txt files: expected command outputs for regression testing
Key insights from README
• “hgit” is just a shell wrapper around git; it delegates to Git, manipulates remotes, opens browser for PRs.
• It reads a user config in ~/.hgitrc containing MY_GITHUB_USER.
• It uses standard git commands and GitHub conventions (forking workflow).
Main components
a. User / Developer CLI
– Terminal where user types “h <command>”
b. hgit.sh script
– Command dispatcher (case statement for subcommands)
– Business logic for each subcommand
– Reads ~/.hgitrc
c. Bash completion engine
– hgit_completion.sh loaded into shell
– Provides tab completion for subcommands and branch names
d. Underlying Git CLI
– git executable invoked by hgit.sh
– Local repository (./.git directory, working tree)
e. Remote GitHub service
– git@github.com or https://api.github.com for fetch/push
– Browser invocation for PR creation
f. CI/Test harness
– tests.sh runs sample commands, compares output against tests/*.txt
– .drone.yml invokes tests.sh on pipeline events
Relationships and interactions
• User → hgit.sh: enters commands; script parses and dispatches
• hgit.sh ↔ ~/.hgitrc: loads user GitHub username
• hgit.sh → git CLI → Local repo: runs git clone/status/diff/commit/branch/push
• hgit.sh → Remote GitHub: fetches forks, opens PR URLs in browser
• hgit_completion.sh ↔ shell: intercepts tab presses, queries hgit.sh for suggestions
• CI system (.drone.yml) → tests.sh → hgit.sh & tests/: validates behavior
Architectural patterns & design principles
• Single‑entry point script with subcommand dispatcher (similar to git’s plugin pattern)
• Separation of concerns:
– Dispatch layer (hgit.sh) vs. completion layer (hgit_completion.sh) vs. tests
• Convention over configuration: opinionated defaults for GitHub workflows
• Stateless operations: each “h” command runs and exits; state is in Git metadata
• Extensibility: adding a new subcommand is as simple as adding a new case branch in hgit.sh