summaryrefslogtreecommitdiffstats
path: root/.local/bin/confgit.sh
blob: 643080b97ee1014194a082cf596427aea37e70ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env sh

VER="$(git version | cut -d " " -f 3)"

# Portably get number of procs
OS="$(uname -s)"
NPROCS=""
if [ "$OS" = "Linux" ]; then
	DETPROCS="$(nproc --all)"
elif [ "$OS" = "Darwin" ] || [ "$(echo "$OS" | grep -q BSD)" = "BSD" ]; then
	DETPROCS="$(sysctl -n hw.ncpu)"
else
	DETPROCS="$(getconf _NPROCESSORS_ONLN)" # glibc/coreutils fallback
fi

if [ $DETPROCS -gt 16 ] && [ "$OS" = "Linux" ]; then
	NPROCS="$(($DETPROCS / 2))"
else
	NPROCS="$DETPROCS"
fi

if [ ! $(command -v git) ]; then
	echo "git not installed"
	exit 1
fi

if [ -e $HOME/.gitconfig ]; then
	rm $HOME/.gitconfig # Purge existing gitconf
fi

# Dotfiles config
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config protocol.version 2
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config branch.main.rebase true
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config branch.trunk.rebase true
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config pull.ff only
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config push.default simple
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config status.showUntrackedFiles no

# Main Git Config
git config --global am.messageid true
git config --global branch.sort -committerdate
git config --global checkout.defaultRemote origin       # Default to using the "origin" remote
git config --global checkout.thresholdForParallelism 50 # Default 100 files
git config --global checkout.workers "$NPROCS"          # Auto-detect threads from CPU
git config --global commit.verbose true
git config --global core.commitgraph true
git config --global core.excludesfile "$HOME/.local/share/git/ignore_global"
git config --global core.pager "less"
git config --global credential.https://source.developers.google.com.helper "gcloud.sh"
git config --global diff.algorithm histogram
git config --global fetch.parallel "$NPROCS"
git config --global fetch.prune true
git config --global fetch.prunetags true
git config --global fetch.writeCommitGraph true
git config --global gc.cruftPacks true
git config --global gc.writeCommitGraph true
git config --global gpg.format ssh
git config --global hub.protocol https
git config --global http.cookiefile "$HOME/.local/share/git/cookies"
git config --global init.defaultBranch main
git config --global index.recordEndOfIndexEntries true
git config --global index.recordOffsetTable true
git config --global log.date iso
git config --global merge.conflictstyle zdiff3
if [ "${VER}" \> "2.45" ]; then
	git config --global pack.allowPackReuse multi # Experimental
	git config --global index.skipHash true       # Experimental, will fail earlier than 2.40
	git config --global index.version 4
	git config --global fetch.negotiationAlgorithm skipping # Experimental
	# Additional experimental configs
	git config --global feature.manyFiles true
fi
git config --global pack.threads "$NPROCS" # Auto-detect threads from CPU
git config --global pack.useBitmapBoundaryTraversal true
git config --global pack.writeReverseIndex true
git config --global protocol.version 2
git config --global pull.ff only
git config --global pull.twohead ort # Use new faster merge algorithm
git config --global push.autoSetupRemote true
git config --global push.default simple
#git config --global push.followTags true
git config --global rerere.enabled true
git config --global rebase.autoStash true
git config --global rebase.missingCommitsCheck error
git config --global rebase.updateRefs true
git config --global status.submodulesummary 1
git config --global tag.sort taggerdate
git config --global user.email tyler@gluecode.net
git config --global user.name "Tyler Davis"

if [ "${VER}" \> "2.47" ] && [ "$(uname -s | grep -q BSD)" ]; then
	# Only enable reftable by default on git 2.47+
	git config --global init.defaultRefFormat reftable
fi

# Eagerly detect errors
git config --global transfer.fsckobjects true
git config --global fetch.fsckobjects true
git config --global receive.fsckObjects true

# Adding signoff for kernel and other work
git config --global format.signoff true

# Tools
git config --global difftool.nvim.cmd "nvim -d \$LOCAL \$REMOTE \$MERGED -c 'wincmd w' -c 'wincmd J'"
git config --global difftool.vscode.cmd "code --wait --diff \$LOCAL \$REMOTE"
git config --global mergetool.vscode.cmd "code --wait \$MERGED"

# Editors
if [ "$(command -v code)" ] && [ "$(env | grep VSCODE)" ]; then
	git config --global core.editor "code --wait"
	git config --global diff.tool vscode
	git config --global merge.tool vscode
else
	if [ "$(command -v nvim)" ]; then
		git config --global core.editor nvim
		git config --global diff.tool nvim
		git config --global merge.tool nvim
	else
		git config --global core.editor vim
		git config --global diff.tool vim
		git config --global merge.tool vim
	fi
fi

# Use pager for large diffs
git config --global pager.difftool true
if [ "$(command -v difft)" ]; then
	git config --global alias.dft difftool
	git config --global diff.external difft
fi

# Git configs applied to folder groups
if [ "$(command -v fd)" ]; then
	if [ -d $HOME/.code/gluecode ]; then
		find $HOME/.code/gluecode -name ".git" -type d -exec sh -c "cd {}; git config user.email tyler@gluecode.com;" \;
	fi
else
	if [ -d $HOME/.code/gluecode ]; then
		find $HOME/.code/gluecode -name ".git" -exec sh -c "cd {}; git config user.email tyler@gluecode.net;" \;
	fi
fi

# Git LFS support
if [ $(command -v git-lfs) ]; then
	# Only install if we don't detect existing LFS entries, which should
	# always be true on a fresh run
	if [ $(git config -l | grep -c lfs) -lt 1 ]; then
		# Redirect output to null - silence "Git LFS installed" messages
		#git lfs install > /dev/null
		git config --global --includes --replace-all filter.lfs.clean "git-lfs clean -- %f"
	fi
fi

case $(uname) in
Darwin)
	git config --global credential.helper osxkeychain
	;;
Linux)
	git config --global credential.helper "store --file=/home/tydavis/.config/gitcreds"
	# Email configuration for `git send-email` command - default Gluecode
	git config --global sendemail.annotate yes # Review and edit each patch
	git config --global sendemail.confirm auto
	git config --global sendemail.smtpserver /usr/bin/msmtp
	;;
FreeBSD)
	git config --global credential.helper "store --file=/home/tydavis/.config/gitcreds"
	# Email configuration for `git send-email` command - default Gluecode
	git config --global sendemail.annotate yes # Review and edit each patch
	git config --global sendemail.confirm auto
	git config --global sendemail.smtpserver /usr/bin/msmtp
	;;
esac