forked from r-three/git-theta
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.sh
61 lines (52 loc) · 1.46 KB
/
utils.sh
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
#!/usr/bin/env bash
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[0;33m"
NORMAL="\033[0m"
function color_echo {
local text="${1}"
local color="${2}"
local newline="${3}"
# If we provide a 3rd argument, don't include the newline, this lets us
# do two colors on one line easily.
if [[ -z "${newline}" ]]; then
echo -e "${color}${text}${NORMAL}"
else
echo -en "${color}${text}${NORMAL}"
fi
}
function green_echo {
local text="${1}"
local newline="${2}"
color_echo "${text}" "${GREEN}" "${newline}"
}
function red_echo {
local text="${1}"
local newline="${2}"
color_echo "${text}" "${RED}" "${newline}"
}
function yellow_echo {
local text="${1}"
local newline="${2}"
color_echo "${text}" "${YELLOW}" "${newline}"
}
function make_repo {
echo "Making Git Repo."
git init 2> /dev/null
git branch -m main
# Set the git user/email for the generated test repo
git config --local user.email "[email protected]"
git config --local user.name "Git Theta Tester"
}
function test_init {
make_repo
if [[ ! ${-} =~ e ]]; then
red_echo "It seems that 'set -e' was not done in this test. This makes it easy for a test to fail but appear to pass. Please add 'set -e' and do specific error handling if a part of your test is allowed to fail."
exit 1
fi
}
function commit {
local msg="${1}"
git commit -m "${msg}" > /dev/null
echo $(git rev-parse HEAD)
}