git-cr/git-cr-new.bash

31 lines
793 B
Bash
Executable File

#!/usr/bin/env bash
################################################################################
# git-cr-new
# Adds a review at HEAD
################################################################################
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
USERNAME=$(git config user.name)
TMP_FILE=".git/REVIEW_EDITMSG.tmp"
MSG_FILE=".git/REVIEW_EDITMSG"
main () {
# Get a formatted patch of the current permit as a starting point for the note
git diff HEAD~1 HEAD | grep -E '^[+-]' | sed -e '/---/i\\' | sed -e 's/^/# /' > "$TMP_FILE"
vi "$TMP_FILE"
# Remove comments
grep -Ev '^#' "$TMP_FILE" > "$MSG_FILE"
# Sign off
echo -e "\n--\nReviewed by $USERNAME\n--\n" >> "$MSG_FILE"
git notes append --file="$MSG_FILE"
}
main