diff --git a/Tools/gittools/git-subsystems-split b/Tools/gittools/git-subsystems-split new file mode 100755 index 0000000000..e1c9a45bb9 --- /dev/null +++ b/Tools/gittools/git-subsystems-split @@ -0,0 +1,93 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE[0]})) +GIT_DIR=$(git rev-parse --git-dir) +GIT_ROOT=$(git rev-parse --show-toplevel) + +MSG_FILE="$GIT_DIR/SUBSYSTEMS_SPLIT_MSG" + +usage() { + cat >&$1 <&2 + exit 1 +fi + +author=$(git log -n 1 --format=%ae) +git log -n 1 --format=%B > "$MSG_FILE" + +if $option_edit; then + if [[ -z $EDITOR ]]; then + echo "Environment variable EDITOR is required for option --edit." >&2 + exit 1 + fi + ($EDITOR "$MSG_FILE") +elif ! $option_copy; then + if head -n 1 "$MSG_FILE" | grep "^[^: ]\+\s*:" -q; then + sed '1 s,^[^: ]\+\s*,$subsystem,' -i "$MSG_FILE" + else + buff_file="$(mktemp)" + awk ' + NR == 1 { + l=sub(/^\s\+/, "", $line); + print "$subsystem: " \ + tolower(substr($l, 1, 1)) \ + substr($l, 2); + } + NR != 1 + ' "$MSG_FILE" > "$buff_file" + mv "$buff_file" "$MSG_FILE" + rm "$buff_file" + fi +fi + +HEAD=$(git rev-parse HEAD) +git reset HEAD~1 --soft +if ! "$SCRIPT_DIR/git-commit-subsystems" -F "$MSG_FILE" --author=$author; then + echo "Error on calling git-commit-subsystems." >&2 + git reset $HEAD + exit 1 +fi