-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit-case-show
executable file
·133 lines (117 loc) · 4.46 KB
/
git-case-show
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
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#
# Assumptions:
# - in a git repository
# - we can access git-case-common
# - the branch defined by GIT_CASE_HEAD exists (see git-case-common)
source $(dirname $0)/git-case-common
SHOW_FILES=true
SHOW_IDS=false
SHOW_COMMENTS=true
while test "${1:0:1}" = "-" ; do
case "$1" in
--files) SHOW_FILES=true ;;
--no-files) SHOW_FILES=false ;;
--ids) SHOW_IDS=true ;;
--no-ids) SHOW_IDS=false ;;
--comments) SHOW_COMMENTS=true ;;
--no-comments) SHOW_COMMENTS=false ;;
--*)
die "usage: $PROGRAM [--comments|--no-comments] [--ids|--no-ids] [--files|--no-files] <caseid>"
;;
esac
shift
done
ID=$1
if test -z "$ID" ; then
ID=$(cat "$GIT_CASE_ACTIVE" 2>/dev/null || true)
test -z "$ID" && die "no active case set"
fi
ID=$(git ls-tree $GIT_CASE_HEAD | awk "/\t${ID}[a-fA-F0-9]*$/"'{ print $4 }')
shortID=$(gen_short_case_id "$ID")
CASE_ROOT="$GIT_CASE_HEAD:${ID}"
desc=$(git show "$CASE_ROOT/description" 2>/dev/null || true)
test -z "$desc" && die "active case is not valid"
cdate=$(git show "$CASE_ROOT/created" 2>/dev/null || true)
ctype=$(git show "$CASE_ROOT/type" 2>/dev/null || true)
state=$(git show "$CASE_ROOT/state" 2>/dev/null || true)
assig=$(git show "$CASE_ROOT/assigned" 2>/dev/null || true)
found=$(git show "$CASE_ROOT/found" 2>/dev/null || true)
found=$(git log -1 --pretty=oneline --abbrev-commit "$found" || echo "$found")
mine=""
if test "$assig" = "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" \
-o "$assig" = "$GIT_COMMITTER_EMAIL" ; then
mine="$bold$blue"
elif test -z "$assig" ; then
mine="$bold$black"
assig="(nobody)"
fi
echo -e "Case ID: $bold$blue$shortID$reset ($white$ID$reset)"
echo -e "Description: $yellow$desc$reset"
echo "Created on: $cdate"
echo "Type: $ctype"
echo "State: $state"
echo -e "Assigned to: $mine$assig$reset"
echo "Found in: $found"
MARKS=$(git ls-tree $GIT_CASE_HEAD "$ID/marks/" | awk -F/ '{ print $3 }' | xargs)
test -n "$MARKS" && echo "Marks: $MARKS"
FIELDS=$(git ls-tree $GIT_CASE_HEAD "$ID/fields/" | awk -F/ '{ print $3 }' | xargs)
if test -n "$FIELDS" ; then
echo
echo "Fields..."
git ls-tree $GIT_CASE_HEAD -- "$ID/fields/" \
| while read mode type object file ; do
if test $type = blob ; then
short=${file##*/}:
printf " * %-10s" $short
git cat-file blob $object | sed 's/^/ /'
fi
done
fi
if $SHOW_FILES ; then
HAVE_FILES=$(git ls-tree $GIT_CASE_HEAD -- "$ID/files")
if test -n "$HAVE_FILES" ; then
echo
echo "Files..."
git ls-tree -r $GIT_CASE_HEAD -- "$ID/files/" \
| grep ' blob ' \
| while read mode type object file; do
name_and_hash=${file#*/*/}
name=${name_and_hash%%/*}
sha1=${name_and_hash#*/}
echo -e " * $bold$black""$sha1 $reset""$name"
done
fi
fi
if $SHOW_IDS ; then
HAVE_IDS=$(git ls-tree $GIT_CASE_HEAD -- "$ID/ids")
if test -n "$HAVE_IDS" ; then
good=$(echo good | git hash-object -t blob --stdin)
echo
echo "IDs..."
git ls-tree $GIT_CASE_HEAD -- "$ID/ids/" \
| grep ' blob ' \
| while read mode type object file ; do
if test "$object" = "$good" ; then
echo -e " good $green$object$reset"
else
echo -e " bad $red$object$reset"
fi
done
fi
fi
if $SHOW_COMMENTS ; then
HAVE_COMMENTS=$(git ls-tree $GIT_CASE_HEAD -- "$ID/comments")
if test -n "$HAVE_COMMENTS" ; then
echo
echo "Comments..."
git ls-tree $GIT_CASE_HEAD -- "$ID/comments/" \
| grep ' blob ' \
| while read mode type object file ; do
if test "$header_done" != no ; then
header_done=yes
fi
print_pretty_comment "$file" "$object"
done
fi
fi