This document provides a technical overview of the git-merged-branches architecture, including its modular structure, dependency relationships, and data flow. It describes how the TypeScript source modules interact to deliver CLI functionality, from validating the repository state to executing Git operations and formatting terminal output.
For detailed information about individual modules and their functions, see:
Sources: package.json1-79 src/index.ts6-31
The codebase is organized into modular TypeScript files within the src/ directory, each with a specific responsibility:
| Module | Purpose | Key Exports |
|---|---|---|
index.ts | Entry point and execution orchestration | main() |
repo.ts | Git repository interaction and configuration loading | isGitRepo(), getMergedBranches(), deleteBranches(), getConfig() |
output.ts | Branch list formatting, remote detection, and display logic | outputMergedBranches(), formatTaskBranches() |
helpers.ts | Text styling, pluralization, and error logging utilities | style, logError(), pluralize() |
validate.ts | URL validation for configuration settings | isValidURL() |
types.ts | Shared TypeScript type definitions | GitMergedConfig, GitMergedOptions |
The build process produces a single executable bundle at dist/index.mjs.
Module Responsibilities Diagram:
Sources: package.json25-28 src/index.ts1-31 src/repo.ts1-101 src/output.ts1-68 src/types.ts1-9
The following diagram illustrates the import relationships between modules, showing how dependencies flow through the system:
Import Analysis:
index.ts imports from helpers, output, and repo to orchestrate the entire workflow src/index.ts2-4output.ts imports from helpers, repo, and validate for formatting and display logic src/output.ts1-4repo.ts imports from helpers for error logging and types for configuration structure src/repo.ts5-6types.ts has no dependencies and provides interfaces for configuration and options src/types.ts1-9Sources: src/index.ts1-4 src/output.ts1-4 src/repo.ts1-6
The system follows a structured flow through validation, Git operations, configuration loading, and output formatting:
Step-by-Step Process:
Validation Phase src/index.ts7-14
isGitRepo() verifies the current directory is a Git repository src/repo.ts8-15isDetachedHead() ensures HEAD points to a branch to prevent execution in a detached state src/repo.ts17-24Target Branch Detection src/index.ts16-20
getDefaultTargetBranch() identifies main or master as the comparison base src/repo.ts35-42Merged Branch Discovery src/index.ts22
getMergedBranches() executes git branch --merged and filters out the target branch itself by comparing commit hashes src/repo.ts44-56Configuration Loading src/index.ts24
getConfig() reads issue tracker settings from the git-merged-branches field in package.json src/repo.ts72-81Output Generation src/index.ts24
outputMergedBranches() formats results and determines which branches also exist on the remote src/output.ts39-67formatTaskBranches() uses regex to find issue IDs and append URLs src/output.ts24-37Optional Deletion src/index.ts23
--delete flag is present, deleteBranches() removes branches locally and remotely src/repo.ts89-100Sources: src/index.ts6-28 src/repo.ts8-100 src/output.ts39-67
The system defines two primary interfaces in src/types.ts that govern configuration and runtime behavior:
GitMergedConfig src/types.ts1-4
issueUrlFormat: A template string (e.g., https://jira.com/{{prefix}}{{id}}) src/output.ts18issueUrlPrefix: An array of strings used to identify task IDs in branch names src/output.ts11-15GitMergedOptions src/types.ts6-8
deleteBranches: A boolean flag derived from the --delete CLI argument src/index.ts23Sources: src/types.ts1-9 src/repo.ts72-81 src/output.ts24-37
The system operates in two distinct modes based on user input:
Lists merged branches, identifies which ones exist on the remote origin, and prints the specific Git commands required to delete them manually src/output.ts60-66
Triggered by the --delete flag. It programmatically executes local and remote deletion commands src/repo.ts83-88 It uses fetchRemoteBranches to ensure remote deletion is only attempted for branches that actually exist on the server src/output.ts52-55
Sources: src/index.ts23-24 src/output.ts39-67 src/repo.ts83-100
The system compiles TypeScript source files into a single executable JavaScript module:
Build Configuration:
tsdown is used to bundle and minify the source package.json38.mjs) targeting Node.js environments package.json26-27bin field in package.json maps both gmb and git-merged-branches to the same entry point package.json25-28Sources: package.json25-38