-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit-case-assign
executable file
·62 lines (49 loc) · 1.66 KB
/
git-case-assign
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
#!/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
function usage() {
OUT=$1
$OUT -e "Usage: $PROGRAM [ [<caseid>] <user> ]
User set to 'me' expands to you; sets to 'none' sets to no one."
exit 0
}
test "$1" = "-h" && usage echo
# argument form is:
# git case assign - display who the active case is assigned to
# git case assign foo@bar - assign the active case to foo@bar
# git case assign caseid foo@bar - assign the caseid case to foo@bar
case "${#@}" in
0|1) ID=$(cat "$GIT_CASE_ACTIVE" 2>/dev/null || true)
test -z "$ID" && die "no active case set"
;;
2) ID="$1"
ID=$(git ls-tree $GIT_CASE_HEAD | awk "/\t${ID}[a-fA-F0-9]*$/"'{ print $4 }')
shift
;;
*) usage die
;;
esac
ASSIGNED_FILE="$ID/assigned"
case "${#@}" in
1) WHO="$1"
;;
*) exec git show "$GIT_CASE_HEAD:$ASSIGNED_FILE"
;;
esac
if test "$WHO" = "me" ; then
WHO="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
elif test "$WHO" = "none" ; then
WHO=
elif ! ( echo "$WHO" | grep -q "@" ) ; then
die "new assignee '$WHO' does not look like an email address"
fi
shortID=$(gen_short_case_id "$ID")
# we work in the working dir
go_to_git_case_work_dir
git read-tree -i --reset "$GIT_CASE_HEAD"
add_file_to_index "$ASSIGNED_FILE" "$WHO"
commit_index_and_update_branch "$shortID assigned to '$WHO'" "-p $GIT_CASE_HEAD"