From b45af8a047ae879c0ce828e2734e10788b6c5f29 Mon Sep 17 00:00:00 2001 From: Dirk Nederveen Date: Tue, 7 Nov 2023 10:44:25 +0100 Subject: [PATCH] Add git-fixup.sh --- README.md | 2 ++ git-fixup.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 git-fixup.sh diff --git a/README.md b/README.md index b104763..b0d90a8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # git-fixup +Link git-fixup.sh somewhere in your `PATH`. +Omit the `.sh` file extension to use `git fixup ` as a shorthand. diff --git a/git-fixup.sh b/git-fixup.sh new file mode 100755 index 0000000..35791f4 --- /dev/null +++ b/git-fixup.sh @@ -0,0 +1,21 @@ +#!/bin/bash -e + +if [[ $# -lt 1 ]]; then + ( + echo "Usage:" + echo " $0 " + ) >&2 + exit 2 +fi + +COMMIT_ID="$1" +shift + +COMMIT_ID="$(git rev-parse "$COMMIT_ID")" +exitcode=$? +if [[ $exitcode -ne 0 ]]; then + echo >&2 "Invalid ref \"$COMMIT_ID\"" + exit 1 +fi + +exec git commit -m "fixup! $COMMIT_ID" "$@"