-
Notifications
You must be signed in to change notification settings - Fork 5
/
git-case-mark
executable file
·46 lines (35 loc) · 1.16 KB
/
git-case-mark
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
#!/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
test -z "$1" && die "$PROGRAM [-d] <mark-name>"
action="set"
if test "$1" = "-d" ; then
action="removed"
shift
fi
MARK="$1"
echo "$MARK" | grep -q '^[a-zA-Z0-9][a-zA-Z0-9._-]*$' || die "format of mark '$MARK' is invalid"
ID=$(cat "$GIT_CASE_ACTIVE" 2>/dev/null || true)
test -z "$ID" && die "no active case set"
shortID=$(gen_short_case_id "$ID")
MARK_FILE="$ID/marks/$MARK"
count=$(git ls-tree $GIT_CASE_HEAD "$MARK_FILE" | wc -l)
if test "$action" = "set" -a "$count" -ne "0" ; then
die "mark '$MARK' already set on case $shortID"
fi
if test "$action" = "removed" -a "$count" -ne "1" ; then
die "no mark '$MARK' set on case $shortID"
fi
# we work in the working dir
go_to_git_case_work_dir
git read-tree -i --reset "$GIT_CASE_HEAD"
if test "$action" = "set" ; then
add_file_to_index "$MARK_FILE" ""
else
git update-index --remove "$MARK_FILE"
fi
commit_index_and_update_branch "mark '$MARK' $action on $ID" "-p $GIT_CASE_HEAD"