# @references:
#    https://git-scm.com/docs/git-config
#    https://dzone.com/articles/how-to-use-gitconfigs-includeif
#
[init]
    defaultBranch = main
#   templatedir = ~/.infra/ansible/roles/base/templates/git/templates/

[user]
    name = Your Name
    email = your.email@example.com
    # signingkey = ABCDEFGH12345678

[includeIf "gitdir/i:~/projects/work/"]
    path = ~/.gitconfig-work
[includeIf "gitdir/i:~/projects/personal/"]
    path = ~/.gitconfig-personal

[commit]
    template = ~/.gitmessage
    gpgsign = true

[gpg]
    program = /usr/local/bin/gpg

[core]
    editor = vim
    autocrlf = input
    ignorecase = false
    excludesfile = ~/.gitignore_global
    # hooksPath = ~/.infra/ansible/roles/base/templates/git/hooks/

[alias]
    # General
    pl = pull
    st = status
    co = checkout
    com = "! f() { git checkout main 2>/dev/null || git checkout master; }; f"
    cob = !git branch -a | fzf | xargs git checkout
    di = diff
    bl = blame
    br = branch
    brc = branch --show-current
    brd = "!f() { git checkout main 2>/dev/null || git checkout master; git branch -d @{-1}; }; f"
    cp = cherry-pick
    ci = commit
    pu = push
    poh = push -u origin HEAD


    # Logging
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
    last = log -1 HEAD

    # Diff
    df = diff
    dc = diff --cached
    d3 = diff --color --diff-algorithm=minimal --word-diff=color --ignore-all-space
    d3c = diff --cached --color --diff-algorithm=minimal --word-diff=color --ignore-all-space
    dim = "!sh -c 'git diff $(git branch -a | sed -n -E -e \"/remotes.origin.ma(in|ster)$/s@remotes/origin/@@p\") HEAD --name-only'"

    # Submodule
    sbi = submodule init
    sbu = submodule update
    sbp = submodule foreach git pull
    sbc = submodule foreach git co master

    # Other
    prq = !sh -c \"git fetch upstream refs/pull/$1/head:pr-$1 && git checkout pr-$1\" -
    dpr = !sh -c “git branch | grep pr- | xargs git branch -D” -
    sync = !sh -c \"git checkout master && git pull upstream master && git push origin HEAD --no-verify\" -

    # Clean up
    done = "!f() { git checkout main && git pull && git branch --merged | grep -v '*' | xargs -n 1 git branch -d; }; f"

[pull]
    rebase = true

[push]
    default = simple
    autoSetupRemote = true

[merge]
    tool = vimdiff
    conflictstyle = diff3

[color]
    ui = auto

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