Git Configuration Based on Tags

Git Configuration Based on Tags

This example shows how to use HermitGrab’s tag system to manage Git configurations for different contexts like work and personal use. It demonstrates the power of tag-based conditional installs and detectors.

Highlights

  • Tag-based Configuration: Select Git config based on +work or +personal.
  • Custom Detectors: Checks for the presence of tools like Git and 1Password.
  • Multi-Context Setup: Automates email, user name, and signing key.
[detectors]
has_1password = { enable_if = "[ -x /Applications/1Password.app/Contents/MacOS/op-ssh-sign ]" }
has_git = { enable_if = "command -v git" }
has_git_lfs = { enable_if = "command -v git-lfs" }

[[install]]
name = "Git Personal Email"
check = "[ $(git config --global --get user.email) = \"[email protected]\" ]"
install = """#!/bin/bash
git config --global user.name \"Definitly Myname\"
git config --global user.email \"[email protected]\"
git config --global user.signingkey \"ssh-ed25519 AAAAC3...\"
"""
requires = ["+personal", "+has_git"]

[[install]]
name = "Git Work Email"
check = "[ $(git config --global --get user.email) = \"[email protected]\" ]"
install = """#!/bin/bash
git config --global user.name \"Definitly Myname\"
git config --global user.email \"[email protected]\"
git config --global user.signingkey \"ssh-ed25519 AAAAC3...\"
"""
requires = ["+work", "+has_git"]

[[install]]
name = "Git LFS config"
check = "[ $(git config --global --get filter.lfs.required) = \"true\" ]"
install = "git lfs install"
requires = ["+has_git", "+has_git_lfs"]