-
Notifications
You must be signed in to change notification settings - Fork 5
/
git-case-new
executable file
·85 lines (72 loc) · 2.12 KB
/
git-case-new
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
#!/bin/bash
#
# Assumptions:
# - in a git repository
# - we can access git-case-common
source $(dirname $0)/git-case-common
test -z "$1" -o "$1" = "-h" \
&& die "$PROGRAM [--me | --assign=<who>]
[--type=<type>]
[--state=<state>]
[<description>|--stdin|-]"
TYPE="bug"
STATE="new"
WHO=""
while test "${1:0:2}" = "--" ; do
case "$1" in
--me) WHO="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
shift
;;
--assign=*)
WHO=${1#*=}
echo "$WHO" | grep -q ".@." \
|| die "new assignee '$WHO' does not look like an email address"
shift
;;
--type=*)
TYPE=${1#*=}
shift
;;
--state=*)
STATE=${1#*=}
shift
;;
esac
done
# we work in the working dir
go_to_git_case_work_dir
DESC="$@"
case "$DESC" in
--stdin)
DESC=$(cat)
;;
-)
DESC_FILE=$(mktemp -p "$GIT_CASE_WORK_DIR")
cat <<END > "$DESC_FILE"
# Type in a one line description for the case above.
# Lines starting with '#' character are ignored.
END
vim $DESC_FILE
DESC=$(grep -v -e "^#" -e "^$" $DESC_FILE)
;;
esac
CASE_ID=$(generate_case_id "$DESC")
shortID=$(gen_short_case_id "$CASE_ID")
COMMIT_PARENT_ARGS=
if test -n "$(git rev-parse --revs-only ${GIT_CASE_HEAD})" ; then
# already initialized, reset index to last commit
git read-tree -i --reset "$GIT_CASE_HEAD"
COMMIT_PARENT_ARGS="-p $GIT_CASE_HEAD"
else
# reset the cache
git read-tree -i --reset $(printf '' | git write-tree)
fi
# build the tree
add_file_to_index "$CASE_ID/description" "$DESC"
add_file_to_index "$CASE_ID/type" "$TYPE"
add_file_to_index "$CASE_ID/state" "$STATE"
echo "$WHO" | add_file_to_index "$CASE_ID/assigned"
git rev-parse HEAD | add_file_to_index "$CASE_ID/found"
date | add_file_to_index "$CASE_ID/created"
commit_index_and_update_branch "$DESC" "$COMMIT_PARENT_ARGS"
echo -e "New case $yellow$shortID$reset created."