Markus Michalski FAQ

git-sync-all: Technical details

How git-sync-all is built: modules, execution order, dry-run wrapper, subshell isolation, lock file, file layout, tests and CI.

Deutsche Version

Back to overview

git-sync-all: Technical details

File layout

git-sync-all/
β”œβ”€β”€ bin/git-sync-all           Entry point
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ core.sh                Strict mode, logging, colors, lock, cleanup
β”‚   β”œβ”€β”€ config.sh              Defaults, config loading, validation, --init-config
β”‚   β”œβ”€β”€ cli.sh                 Arguments, help, version, alias
β”‚   β”œβ”€β”€ repo-discovery.sh      Repository search, filters, remote check
β”‚   β”œβ”€β”€ git-ops.sh             Git operations, dry-run wrapper
β”‚   β”œβ”€β”€ sync.sh                Sync flow, prompts, status, summary
β”‚   β”œβ”€β”€ inventory.sh           repos.yml, --verify, cleanup, --init-inventory
β”‚   └── issues.sh              GitHub issues via gh
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ config.conf.example
β”‚   └── repos.yml.example
β”œβ”€β”€ tests/                     Test scripts
β”œβ”€β”€ Makefile                   install, uninstall, link, test, lint, format
└── install.ps1                Windows installer

Execution order

graph TD
    A[parse_args] --> B[load_config]
    B --> C[apply_cli_overrides]
    C --> D[setup_environment: colors, git check, lock]
    D --> E{Mode}
    E -->|--verify| F[parse_inventory and verify_inventory]
    E -->|--issues| G[parse_inventory and show_issues]
    E -->|default| H[discover_repos]
    H --> I{--status?}
    I -->|yes| J[show_status]
    I -->|no| K[sync_all]
    J --> L[print_summary]
    K --> L
    L --> M{Failed greater than 0?}
    M -->|yes| N[Exit 1]
    M -->|no| O[Exit 0]

--help, --version, --init-config, --setup-alias and --init-inventory already end the tool inside parse_args. The lock is acquired before every mode, so also for --status, --verify and --issues.

Modules

File Responsibility
bin/git-sync-all Resolves its own path (also through symlinks), sources all libraries and drives main().
lib/core.sh set -euo pipefail, colors, logging to stderr, cleanup trap, git check, lock file.
lib/config.sh Defaults, loading the config via source, validation, --init-config.
lib/cli.sh parse_args, apply_cli_overrides, help text, --setup-alias.
lib/repo-discovery.sh find search for .git directories, include/exclude filters, remote check.
lib/git-ops.sh All Git calls, conflict detection, aborting rebase and merge, stash.
lib/sync.sh sync_repository, sync_all, prompts, status table, summary.
lib/inventory.sh Inventory parser, verify_inventory, detection and removal of unlisted repositories.
lib/issues.sh show_issues via the GitHub CLI.

Design decisions

Tests and CI

make test starts tests/run-tests.sh, which runs all tests/test-*.sh files. The tests cover CLI parsing, config, repository discovery, Git operations, conflict handling, the inventory and the Windows installer. make lint runs ShellCheck, make format checks with shfmt -i 4 -ci -bn, and make check runs everything together. The GitHub Actions pipeline runs ShellCheck, shfmt, PSScriptAnalyzer for install.ps1 and the tests on Ubuntu and Windows.