diff --git a/bin/git-cp b/bin/git-cp index cabb564b..25732243 100755 --- a/bin/git-cp +++ b/bin/git-cp @@ -4,17 +4,32 @@ set -euo pipefail PROGRAM=$0 CURRENT_FILENAME="" DESTINATION_FILENAME="" +COMMIT_TEMPLATE="{}" + +function commit_message() +{ + # Replace every {} in the template with the default commit message + printf '%s\n' "${COMMIT_TEMPLATE//\{\}/"$1"}" +} function usage() { - echo 1>&2 "USAGE: ${PROGRAM} CURRENT_FILENAME DESTINATION_FILENAME" + echo 1>&2 "USAGE: ${PROGRAM} [--commit-template TEMPLATE] CURRENT_FILENAME DESTINATION_FILENAME" } while [[ $# -gt 0 ]] do key="$1" - if [[ "$CURRENT_FILENAME" == "" ]]; then + if [[ "$key" == "--commit-template" ]]; then + if [[ $# -lt 2 ]]; then + usage + exit 30 + fi + COMMIT_TEMPLATE=$2 + shift 2 + continue + elif [[ "$CURRENT_FILENAME" == "" ]]; then CURRENT_FILENAME=$key elif [[ "$DESTINATION_FILENAME" == "" ]]; then DESTINATION_FILENAME=$key @@ -62,15 +77,15 @@ else # Move the original file to the new destination, in this branch git mv "${CURRENT_FILENAME}" "${DESTINATION_FILENAME}" - git commit -nm "--Duplicate $CURRENT_FILENAME history into $DESTINATION_FILENAME" + git commit -nm "$(commit_message "--Duplicate $CURRENT_FILENAME history into $DESTINATION_FILENAME")" # Restore the original file to keep it in the history git checkout HEAD~ "${CURRENT_FILENAME}" - git commit -nm "--Restore $CURRENT_FILENAME" + git commit -nm "$(commit_message "--Restore $CURRENT_FILENAME")" # Switch to the original branch and merge this back in. git checkout - - git merge --no-ff "$BRANCH_NAME" -m "Copy $CURRENT_FILENAME into $DESTINATION_FILENAME" + git merge --no-ff "$BRANCH_NAME" -m "$(commit_message "Copy $CURRENT_FILENAME into $DESTINATION_FILENAME")" # We're now done with the branch, so delete it. # We shouldn't need -D here, as we've already merged it back in. diff --git a/man/git-cp.1 b/man/git-cp.1 index d9a17093..15f52fcd 100644 --- a/man/git-cp.1 +++ b/man/git-cp.1 @@ -1,12 +1,14 @@ .\" generated with Ronn-NG/v0.9.0 .\" http://github.com/apjanke/ronn-ng/tree/0.9.0 -.TH "GIT\-CP" "1" "March 2020" "" "Git Extras" +.TH "GIT\-CP" "1" "October 2026" "" "Git Extras" .SH "NAME" \fBgit\-cp\fR \- Copy a file keeping its history .SH "SYNOPSIS" -\fBgit\-cp\fR +\fBgit\-cp\fR [\-\-commit\-template