-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-test
executable file
·76 lines (64 loc) · 1.6 KB
/
git-test
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
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-only
# Copyright 2016, Mattias Bengtsson <[email protected]>
set -e
set -o pipefail
function _help-flag {
[[ " ${*} " == *" --help "* ]] || [[ " ${*} " == *" -h "* ]]
}
function _usage {
echo "Usage: git test commit [<msg>]"
echo
echo "Add a series of test commits."
}
function _init {
if _help-flag "${@}"; then
echo "Usage: git test init"
echo
echo "Initialize a test repository."
exit 2
fi
git init
echo "Test repo" > README.md
git add README.md
git commit -m "Initial commit"
}
function _commit {
local branch
if _help-flag "${@}"; then
_usage
exit
fi
# Check that we're inside a git worktree
git rev-parse --is-inside-work-tree >/dev/null
if [ -z "${*}" ]; then
_usage
exit 2
fi
for msg in "$@"; do
branch=$(git rev-parse --abbrev-ref HEAD | sed -e 's/\//--/gi')
echo "${branch}: Commit ${msg}" >> "commits.${branch}"
git add "commits.${branch}"
git commit -a -m "${branch}: Commit ${msg}" -m "This is a test commit!"
done
};
arg="${1}"
shift
case "${arg}" in
init)
_init "${@}"
;;
commit)
_commit "${@}"
;;
*)
echo "Usage: git test [command] [<arg>..]"
echo
echo " git test helps you quickly whip up a repo and some commits."
echo
echo "Commands:"
echo " init Initialize a test repo"
echo " commit Add some test commits"
exit 2
;;
esac