-
Notifications
You must be signed in to change notification settings - Fork 5
/
git-case-ids
executable file
·71 lines (55 loc) · 1.7 KB
/
git-case-ids
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
#!/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 [-l] [ [-g|-b|-d] [<commitish>|-] [<comment>] ]
-l list commits for active case
-g good commit
-b bad commit
-d remove a commit
using - for the <commitish> will use repo HEAD"
CMD=$1 ; shift
VALUE=
case "$CMD" in
-g) CMD="good" ;; # good
-b) CMD="bad" ;; # bad
-d) CMD="deleted" ;; # ugly^wdelete
-l) ;; # list
*) die "invalid mode '$CMD'" ;;
esac
CASE_ID=$(cat "$GIT_CASE_ACTIVE" 2>/dev/null || true)
test -z "$CASE_ID" && die "no active case set"
IDS_PATH="$CASE_ID/ids"
if test "$CMD" = '-l' ; then
good=$(echo good | git hash-object -t blob --stdin)
git ls-tree $GIT_CASE_HEAD -- "$IDS_PATH/" \
| 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
exit 0
fi
HASH=$1 ; shift
if test "$HASH" = "-" ; then
HASH="HEAD"
fi
HASH=$(git rev-parse "$HASH")
HASH_FILE="$IDS_PATH/$HASH"
COMMENT="$@"
# we work in the working dir
go_to_git_case_work_dir
git read-tree -i --reset "$GIT_CASE_HEAD"
if test "$CMD" = "deleted" ; then
git update-index --remove "$HASH_FILE"
else
add_file_to_index "$HASH_FILE" "$CMD"
fi
commit_index_and_update_branch "id '$HASH' $CMD on $CASE_ID
$COMMENT" "-p $GIT_CASE_HEAD"