[alias]
    # Helpers for quoting/unquoting git aliases, from https://stackoverflow.com/questions/38057261/git-config-alias-escaping
    alias = "!sh -c '[ $# = 2 ] && git config --global alias.\"$1\" \"$2\" && exit 0 || echo \"usage: git alias <new alias> <original command>\" >&2 && exit 1' -"
    aliases = "!echo [alias]; git config --get-regexp 'alias[.].*' | sed -E 's/alias[.]([^[:space:]]+)/\t\\1 =/'"
    assign-pr = "!f() { PR=\"$1\"; shift; BR=\"${1:-$(git symbolic-ref HEAD | sed 's#refs/heads/##')}\"; git config \"branch.${BR}.github-pr-owner-number\" \"$(gh repo view --json nameWithOwner -q '.nameWithOwner' | tr '/' '#')#$PR\"; }; f"
    bc = branch-clean
    bpull = !sh -c 'git fetch origin $1:$1' -
    ci = commit
    clean-branches = !git branch --merged origin/\"$(git default-branch)\" | egrep -v \"[*+]|$(git default-branch)\\$\" | xargs -n 1 git branch --delete
    clean-gone = !git branch --format '%(refname:short) %(upstream:track)' | awk '$2 == \"[gone]\" { print $1 }' | xargs -n 1 git branch -D
    co = checkout
    conflicts = !sh -c 'git diff --name-only --diff-filter=U --line-prefix="$(git rev-parse --show-toplevel)/"'
    copy = !fish -c \"git diff --unified=3 $argv | fish_clipboard_copy\" --
    cp = cherry-pick
    default-branch = !git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
    delete = branch -d
    dir-diff = ! COMPARE_FOLDERS=DIFF git difftool --dir-diff
    fpush = push --force-with-lease
    git = !git
    hardreset = reset --hard @{u}
    last = log -1 HEAD
    ld = log --pretty=format:\"%C(yellow)%h\\ %ad%C(red)%d\\ %C(reset)%s%C(blue)\\ [%cn]\" --decorate --date=relative
    lg = !bash -c 'git log --reverse --no-merges --pretty=format:\"%C(yellow)%h %C(reset)%s\" --decorate \"${1:-$(git default-branch)}\"..HEAD' -
    ls = ls-files
    paste = !fish -c \"fish_clipboard_paste | git apply $argv\" --
    pfetch = fetch -p
    ppull = pull -p --no-recurse-submodules
    quote-string = "!read -r l; printf \\\"!; printf %s \"$l\" | sed 's/\\([\\\"]\\)/\\\\\\1/g'; printf \" #\\\"\\n\" #"
    quote-string-undo = "!read -r l; printf %s \"$l\" | sed 's/\\\\\\([\\\"]\\)/\\1/g'; printf \"\\n\" #"
    rb = "rebase"
    rc = rebase --continue
    recommit = !git commit -eF \"$(git rev-parse --git-dir)/COMMIT_EDITMSG\"
    ri = "rebase --interactive --keep-base"
    softreset = reset --soft HEAD~
    ssw = sswitch
    sswitch = !sh -c 'git stash && git switch \"$@\" && git stash pop' -
    st = status
    su = submodule update
    sw = switch
    unstage = reset HEAD --
    vdiff = difftool -d HEAD
[tag]
    sort = version:refname
[core]
    # editor unset, rely on $EDITOR to be set to my preference
    quotePath = true
    protectNTFS = false
    longpaths = true
    autocrlf = input # TODO: double check this in windows/wsl/etc
    symlinks = true
[column]
    ui = auto
[diff]
    tool = code
    context = 5
    algorithm = histogram
    colorMoved = plain
    # May not necessarily want to keep this one:
    mnemonicPrefix = true
    renames = true
[color "diff"]
	context = default
	plain = default
	frag = default
[difftool]
    trustExitCode = true
    prompt = false
[difftool "vimdiff"]
    cmd = vim -c "\"DirDiff $LOCAL $REMOTE\""
[difftool "code"]
    cmd = code --wait --diff --new-window $LOCAL $REMOTE
[merge]
    renameLimit = 2000
    autoStash = true
	conflictStyle = diff3
[submodule]
    recurse = true
[push]
    # Override 'submodule.recurse' to make rpush work without warnings
    recurseSubmodules = no
    autoSetupRemote = true
    default = current
[pull]
    rebase = false
[commit]
    gpgsign = true
    verbose = true
[gpg]
    program = gpg
[checkout]
    defaultRemote = origin
[init]
    defaultBranch = main
[fetch]
    recurseSubmodules = no
[protocol "file"]
    allow = always
[gui]
    editor = code
[advice]
    detachedHead = false
[help]
    autocorrect = prompt
[rerere]
    enabled = true
    autoupdate = true
[rebase]
    autoSquash = true
    autoStash = true
    updateRefs = true
[filter "lfs"]
    required = true
    # Don't configure process filter, my wrapper doesn't work with it
    smudge = ~/.local/bin/git-lfs-wrapper smudge -- %f
    clean = ~/.local/bin/git-lfs-wrapper clean -- %f
[lfs]
    # Don't hard-fail if some LFS files can't be downloaded during checkout.
    # Without this, git repo is left in partially checked out state and it sucks
    skipdownloaderrors = true

[merge "mergiraf"]
	name = mergiraf
	driver = mergiraf merge --git %O %A %B -s %S -x %X -y %Y -p %P -l %L

# NOTE: This has to come last to override other settings, e.g. user.email
[include]
    path = ~/.gitconfig.local
    path = ~/.config/git/config.local

# Bring it back to personal config when we're dealing with public github repos
[includeIf "hasconfig:remote.*.url:git@github.com:*/**"]
    path = "~/.config/yadm/alt/.gitconfig.local##class.personal"
[includeIf "hasconfig:remote.*.url:https://github.com/**"]
    path = "~/.config/yadm/alt/.gitconfig.local##class.personal"
