-
Notifications
You must be signed in to change notification settings - Fork 5
/
git-case-edit-description
executable file
·48 lines (34 loc) · 1.14 KB
/
git-case-edit-description
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
#!/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
ID=$(cat "$GIT_CASE_ACTIVE" 2>/dev/null || true)
test -z "$ID" && die "no active case set"
shortID=$(gen_short_case_id "$ID")
# we work in the working dir
go_to_git_case_work_dir
DESC_FILE="$ID/description"
TEMP_FILE=$(mktemp -p "$GIT_CASE_WORK_DIR")
OLD=$(git show "$GIT_CASE_HEAD:$DESC_FILE")
cat <<END > "$TEMP_FILE"
${OLD}
# Edit the description for case $(gen_short_case_id $ID) above.
# Lines starting with '#' character are ignored.
# To cancel out of an edit, save an empty line.
END
vim $TEMP_FILE
NEW=$(grep -v ^# "$TEMP_FILE")
test -z "$NEW" && die "Refusing to use an empty line as description."
test -z "$NEW" && die "Refusing to use an empty line as description."
if test "$OLD" = "$NEW" ; then
echo "No changes made." >&2
exit 0
fi
git read-tree -i --reset "$GIT_CASE_HEAD"
add_file_to_index "$DESC_FILE" "$NEW"
commit_index_and_update_branch "description changed for case $shortID
was: $OLD
new: $NEW" "-p $GIT_CASE_HEAD"