-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.sh
More file actions
122 lines (101 loc) · 3.64 KB
/
git.sh
File metadata and controls
122 lines (101 loc) · 3.64 KB
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
#!/usr/bin/env -S bash -e
#
# Git functions for Bash.
#
# @package Bash
# @author Kai Kimera <mail@kai.kim>
# @copyright 2023 iHub TO
# @license MIT
# @version 0.0.1
# @link https://lib.onl
# -------------------------------------------------------------------------------------------------------------------- #
(( EUID == 0 )) && { echo >&2 'This script should not be run as root!'; exit 1; }
# -------------------------------------------------------------------------------------------------------------------- #
# EXT scripts.
# -------------------------------------------------------------------------------------------------------------------- #
git="$( command -v git )"
date="$( command -v date )"
tr="$( command -v tr )"
_timestamp() {
${date} -u '+%Y-%m-%d %T'
}
_build_version() {
${date} -u '+%Y%m%d%H%M%S'
}
pushd() {
builtin pushd "$@" > /dev/null 2>&1 || exit 1
}
popd() {
builtin popd > /dev/null 2>&1 || exit 1
}
# -------------------------------------------------------------------------------------------------------------------- #
# Git push.
# -------------------------------------------------------------------------------------------------------------------- #
run.git.push() {
name=$( basename "${PWD}" )
ts="$( _timestamp )"
commit="$*"
echo '' && echo "--- OPEN: '${name}'"
${git} add . \
&& ${git} commit -a -m "${ts}" -m "${commit}" \
&& ${git} push
echo "--- DONE: '${name}'" && echo ''
}
# -------------------------------------------------------------------------------------------------------------------- #
# Git push all.
# -------------------------------------------------------------------------------------------------------------------- #
run.git.push.all() {
for i in *; do
if [[ -d "${i}/.git" ]]; then
pushd "${i}" \
&& run.git.push "$@" \
&& popd || exit 1
fi
done
}
# -------------------------------------------------------------------------------------------------------------------- #
# Git push tag.
# -------------------------------------------------------------------------------------------------------------------- #
run.git.push.tag() {
tags="$( ${git} tag --list )"
changes="$( ${git} status --porcelain )"
[[ -z "${changes}" ]] && count='0' || count='1'
if [[ -z "${1}" ]]; then
if [[ -z "${tags}" ]]; then
version='1.0.0'
else
tag=( "$( ${git} describe --abbrev=0 --tags | ${tr} '.' ' ' )" )
major=${tag[1]}
minor=${tag[2]}
patch=${tag[3]}
version="${major}.${minor}.(( ${patch} + ${count} ))"
fi
else
version="${1}"
fi
run.git.push "$@" \
&& ${git} tag -a "${version}" -m "Version ${version}" \
&& ${git} push origin "${version}"
}
# -------------------------------------------------------------------------------------------------------------------- #
# Git push page.
# -------------------------------------------------------------------------------------------------------------------- #
run.git.push.page() {
[[ -z "${1}" ]] && branch='page-stable' || branch="${1}"
run.git.push "$@" \
&& ${git} checkout main \
&& ${git} merge "${branch}" \
&& ${git} push \
&& ${git} checkout "${branch}"
}
# -------------------------------------------------------------------------------------------------------------------- #
# Git push CDN.
# -------------------------------------------------------------------------------------------------------------------- #
run.git.push.cdn() {
[[ -z "${1}" ]] && branch='cdn-stable' || branch="${1}"
run.git.push "$@" \
&& ${git} checkout main \
&& ${git} merge "${branch}" \
&& ${git} push \
&& ${git} checkout "${branch}"
}