[user]
	name = Fabian Peter Hammerle
	email = fabian@hammerle.me
	signingkey = 8D2902FE7DF47DDEDA2802F9456B9A0399A5DA2F

[core]
	excludesfile = ~/.config/git/gitignore
	# hooksPath = ~/.config/git/hooks

[interactive]
	singleKey = true

[init]
	defaultBranch = main

[status]
	branch = true
	short = true
	showUntrackedFiles = normal

[grep]
	lineNumber = true

[diff]
	tool = vimdiff

[diff "cat"]
	textconv = cat

[diff "csv-to-yaml"]
	textconv = csv-to-yaml

[diff "db_dump"]
	textconv = db_dump

[diff "gpg-show-keys"]
	textconv = gpg --show-keys --with-subkey-fingerprint --with-keygrip --

[diff "gpg-verify"]
	textconv = gpg --verify --output=- 2>&1 --

[diff "hexdump"]
	textconv = od -t x1z --

[filter "home-assistant-analytics"]
	clean = jq '.data.submission_identifier |= if . != null then \"…\" else . end'
	smudge = cat
	required = true

[filter "home-assistant-auth"]
	clean = jq '.data.refresh_tokens |= if . != null then \"…\" else . end'
	smudge = cat
	required = true

[filter "home-assistant-backup"]
	clean = "jq 'reduce ([\"data\", \"backups\"], [\"data\", \"config\", \"last_attempted_automatic_backup\"], [\"data\", \"config\", \"last_completed_automatic_backup\"], [\"data\", \"config\", \"create_backup\", \"password\"]) as $p (.; if getpath($p) != null then setpath($p; \"…\") else . end)'"
	smudge = cat
	required = true

[filter "home-assistant-config-entries"]
	clean = "jq '(.data.entries[].data |= with_entries(if (.key | IN(\"password\", \"access_token\", \"noise_psk\", \"token\", \"webhook_id\")) and .value != null then .value = \"…\" else . end)) | (.data.entries[].unique_id |= if . != null then sub(\"^(?<p>io[.]homeassistant[.]companion[.]android-[[:xdigit:]]{2})[[:xdigit:]]{14}$\"; \"\\(.p)…\") else . end) | ((.data.entries[] | select(.data.app_id == \"io.homeassistant.companion.android\") | .data.device_id) |= if . != null then sub(\"^(?<p>[[:xdigit:]]{2})[[:xdigit:]]{14}$\"; \"\\(.p)…\") else . end) | ((.data.entries[] | select(.domain == \"samsungtv\") | .unique_id) |= if . != null then sub(\"^(?<p>[[:xdigit:]]{2})[[:xdigit:]]{6}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}$\"; \"\\(.p)…\") else . end)' | eval \"$(git config --get filter.truncate-mac-address-to-24-bits.clean)\" | eval \"$(git config --get filter.truncate-dyness-battery-serial-numbers.clean)\""
	smudge = cat
	required = true

[filter "home-assistant-device-registry"]
	required = true
	clean = "jq '(.data.devices[] |= if .manufacturer == \"Victron Energy BV\" then (.name, .serial_number) |= if . != null then sub(\"(?<p>HQ[0-9]{4}[[:alnum:]])[[:alnum:]]{4}(?=[^[:alnum:]]|$)\"; \"\\(.p)…\") else . end elif .manufacturer == \"Valetudo\" then .configuration_url |= if . != null then sub(\"(?<p>://valetudo-[[:alnum:]]{2})[[:alnum:]]+\"; \"\\(.p)…\") else . end else . end) | ((.data.devices[]?, .data.deleted_devices[]?) | .identifiers[]? | select(.[1] != null)) |= if .[0] == \"mobile_app\" then .[1] |= sub(\"^(?<p>[[:xdigit:]]{2})[[:xdigit:]]{14}$\"; \"\\(.p)…\") elif .[0] == \"matter\" then .[1] |= (sub(\"^(?<p>deviceid_[[:xdigit:]]{6})[[:xdigit:]]{10}(?=-)\"; \"\\(.p)…\") | sub(\"^(?<p>serial_[[:xdigit:]]{6})[[:xdigit:]]+$\"; \"\\(.p)…\")) else . end' | eval \"$(git config --get filter.truncate-mac-address-to-24-bits.clean)\" | eval \"$(git config --get filter.truncate-dyness-battery-serial-numbers.clean)\""
	smudge = cat

[filter "truncate-dyness-battery-serial-numbers"]
	clean = sed -E -e 's/(^|[^[:alnum:]])([Bb][0-9]{6})[0-9]{7}([^[:alnum:]]|$)/\\1\\2…\\3/g'
	smudge = cat
	required = true

[filter "truncate-mac-address-to-24-bits"]
	clean = sed -E     -e 's/(^|[^[:xdigit:]:])([[:xdigit:]]{2}(:[[:xdigit:]]{2}){2})(:[[:xdigit:]]{2}){3}([^[:xdigit:]:]|$)/\\1\\2:…\\5/g'     -e 's/(-[[:xdigit:]]{4}-40e7-(8e6c|9f6c)-[[:xdigit:]]{6})[[:xdigit:]]{6}([^[:xdigit:]]|$)/\\1…\\3/gI'     -e 's/(:[[:xdigit:]]{0,4}:[[:xdigit:]]{0,2}ff:fe)[[:xdigit:]]{2}:[[:xdigit:]]{1,4}([^[:xdigit:]:]|$)/\\1…\\2/gI'     -e 's/(^|[^[:xdigit:]-])([[:xdigit:]]{6})[[:xdigit:]]{6}([^[:xdigit:]]|$)/\\1\\2…\\3/g'
	smudge = cat
	required = true

[diff "yq"]
	textconv = yq --yaml-output --indentless-lists . --

[diff "openssl-x509-text"]
	textconv = "sh -c 'while openssl x509 -noout -text; do echo; done' <\"$1\" 2>&1"

[diff "pandas-parquet-to-json"]
	# g+r for podman container
	# https://git.hammerle.me/fphammerle/setup/commit/9c7167b9a9f7e5829d1fba5006b104ab72f6d13a
	textconv = "chmod g+r \"$1\" && env --debug -- pandas-parquet-to-json"

[diff "pgpdump"]
	textconv = pgpdump

[diff "xzcat"]
	textconv = xzcat

[diff "zcat"]
	textconv = zcat

[filter "ipynb"]
	clean = jq --indent 1 '.cells[].id? = null | (.cells[].outputs[].data[\"application/vnd.jupyter.widget-view+json\"]|objects|select(has(\"model_id\"))).model_id |= null'

[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true

[filter "meshtastic-firmware-config"]
    clean = "yq --yaml-output --indentless-lists '.channel_url = \"…\" | .config.bluetooth.fixedPin = \"…\" | .module_config.ambientLighting.blue = \"…\" | .module_config.ambientLighting.green = \"…\" | .module_config.ambientLighting.red = \"…\"' --"

[commit]
	gpgsign = true
	verbose = true

[rebase]
	instructionFormat = %G? %s (%an <%ae>, %ai)
	autostash = true

[push]
	default = current

[url "git@git.hammerle.me:"]
	pushInsteadOf = https://git.hammerle.me/

[url "git@github.com:"]
	pushInsteadOf = https://github.com/

[tag]
	forceSignAnnotated = true

[log]
	date = iso8601-strict

[gcrypt]
	participants = 8D2902FE7DF47DDEDA2802F9456B9A0399A5DA2F
	publish-participants = false

[annex]
	securehashesonly = true
	autocommit = false
	synccontent = true
	# copy instead of hard-linking when unlocking
	thin = false
	# assistant: do not auto delete unused files
	expireunused = false
	# fixes sync of repos inside encfs mounts
	ssh-options = -S~/.ssh/%r@%n:%p

[alias]
	a = add
	c = commit
	# git curl-github-api /commits/master/statuses | jq '.[].state'
	curl-github-api = "!f() { path="$1"; shift; git github-repo-names | xargs -I{} --verbose curl --header 'Accept: application/vnd.github.v3+json' 'https://api.github.com/repos/{}'\"$path\" "$@"; }; f"
	# git curl-github-ref-status dev | jq '{state, statuses, commit_url}'
	curl-github-ref-status = "!f() { ref="$1"; shift; git curl-github-api "/commits/$ref/status" "$@"; }; f"
	d = diff
	f = fetch --prune
	github-repo-names = !git github-urls | grep --only-matching --perl-regexp 'github.com/\\K.+(?=\\.git)'
	github-urls = !git remote-urls | grep ^https://github.com/
	p = push --verbose
	remote-urls = !git remote | xargs -L1 git remote get-url
	s = status
	t = for-each-ref --sort taggerdate --format '%(taggerdate:iso) %(objectname) %(tag)' refs/tags
	tree = log --graph --format=format:'%C(red)%G?%C(reset) %C(yellow)%h%C(reset)%C(blue)%d%C(reset) %C(dim green)%ar%C(reset) %C(white)%s%C(reset) %C(dim cyan)(%an, %ai)%C(reset)' --all
	x = annex
