# vim: ft=gitconfig

[alias]
	root = rev-parse --show-toplevel

	abandon = !git reset --hard HEAD && git clean -d -f
	uncommit = !git reset --soft HEAD~1 && git unstage
	unstage = reset -q HEAD --

	amend = commit --amend
	unamend = !git diff $(git reflog -2 | \
		awk \"{print \\$1}\" | \
		sed -e ':a' -e 'N' -e '$!ba' -e 's/\\n/../g') | \
		git apply - 2> /dev/null || \
			echo "\\\\033[31merror:\\\\033[39m last commit was not amended"
	fixup = commit --fixup
	squash = commit --squash
	prepare = rebase -i --fork-point

	list = branch
	local = !git branch -vv | \
		cut -c 3- | \
		awk '$3 !~/\\[/ { print $1 }'
	recent = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | \
		grep 'checkout:' | \
		grep -oE '[^ ]+ ~ .*' | \
		awk -F~ '!seen[$1]++' | \
		head -n 10 | \
		awk -F ' ~ HEAD@{' '{printf(\"  %s \\033[33m%s\\033[0m\\n\", $1, substr($2, 1, length($2)-1))}'
	create = checkout -b
	delete = branch -D
	refname = rev-parse --abbrev-ref HEAD

	publish = !git push -u `git config --get publish.remote || echo origin` `git refname`
	unpublish = !git push -u `git config --get publish.remote || echo origin` :`git refname`
	force = push --force-with-lease

	changes = !sh -c 'git log --oneline $1..' --
	touched = diff-tree --no-commit-id --name-only -r
	tree = log --graph --format=format:'%C(yellow)%h%C(reset) \
%C(blue)%aD%C(reset) %C(green)(%ar)%C(reset)%C(bold)%d%C(reset)%n        \
%C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
	tracking = rev-parse --abbrev-ref --symbolic-full-name @{u}

	save = commit -m "temp!"
	load = !sh -c '[ \"temp!\" = \"`git show --format=%s --no-patch`\" ] && \
		git reset --mixed HEAD~ || echo \"\\033[31merror:\\033[39m commit subject is not: temp!\"'

[core]
	excludesfile = ~/.config/git/excludes

[init]
	defaultBranch = main

[branch]
	sort = -committerdate

[fetch]
	prune = true

[help]
	autocorrect = -1

[pager]
	status = true

[push]
	default = simple

[pull]
	rebase = false

[rebase]
	autoSquash = true

[user]
	useConfigOnly = true

[diff]
	tool = vimdiff
	algorithm = patience
[difftool]
	prompt = false

[merge]
	tool = vimdiff2
	algorithm = patience
[mergetool]
	prompt = false

[include]
	path = ~/.config/private/gitconfig
	path = ~/.config/work/gitconfig
	path = ~/.config/git/local

[advice]
	skippedCherryPicks = false
