summaryrefslogtreecommitdiff
path: root/.gitcheck
blob: f5db1f2004cb89e42c3aaa684e2239e76c2f480e (plain)
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
#!/bin/sh
# SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
# SPDX-License-Identifier: GPL-3.0-only

git_name="lbmkplaceholder"
git_email="placeholder@lbmkplaceholder.com"

main()
{
	if [ $# -gt 0 ]; then
		if [ "${1}" = "clean" ]; then
			clean
		fi
	else
		set_placeholders
	fi
}

set_placeholders()
{
	set_git_credentials

	# Check coreboot as well to prevent errors during building
	if [ ! -d coreboot ]; then
		return
	fi
	for x in coreboot/*; do
		if [ ! -d "${x}" ]; then
			continue
		fi
		cd "${x}"
		set_git_credentials
		cd -
	done
}

set_git_credentials()
{
	# Check if username and or email is set.
	if ! git config user.name || git config user.email ; then
		git config user.name \
				|| git config user.name "${git_name}"
		git config user.email \
				|| git config user.email "${git_email}"
	fi
}

clean()
{
	unset_placeholders

	if [ ! -d coreboot ]; then
		return
	fi
	for x in coreboot/*; do
		if [ ! -d "${x}" ]; then
			continue
		fi
		cd "${x}"
		unset_placeholders
		cd -
	done
}

unset_placeholders()
{
	if [ "$(git config user.name)" = "${git_name}" ]; then
		git config --unset user.name
	fi

	if [ "$(git config user.email)" = "${git_email}" ]; then
		git config --unset user.email
	fi
}

main $@