From 795049671b883c986411fb531ef0c14c2be78b49 Mon Sep 17 00:00:00 2001 From: David Keijser Date: Tue, 7 Jan 2025 13:27:54 +0100 Subject: [PATCH 1/2] Make commit format configurable Fixes #48 Fixes #58 --- README.md | 11 +++++++++++ git-fixup | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 206574a..45a78db 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,17 @@ Or `GITFIXUPBASE` The default argument for `--base`. You can set the value `closest` to make `git-fixup` use the closest ancestor branch by default, for example. +### fixup.format + +Or `GITFIXUPFORMAT` + +The format string used to display fixup candidates. This is passed to `git log` +and as such supports the same format options as git itself with one minor +alteration: The string 'TYPE' is replaced by the source of the candidate, 'F' +for file, or 'L' for line. + +Refer to the git manual for details. + ### fixup.action Or `GITFIXUPACTION` diff --git a/git-fixup b/git-fixup index b3da477..850b5ea 100755 --- a/git-fixup +++ b/git-fixup @@ -69,8 +69,18 @@ fixup_candidates_all_commits () { print_sha () { local sha=$1 local type=$2 + local format='' - git --no-pager log --format="%h %ai [$type] %s <%ae>" -n 1 "$sha" + case "$type" in + F) + format="$formatf" + ;; + L) + format="$formatl" + ;; + esac + + git --no-pager log --format="$format" -n 1 "$sha" } # Call git commit @@ -180,6 +190,10 @@ base=${GITFIXUPBASE:-$(git config --default="" fixup.base)} show_all=false sort_flags="-k2 -k3 -k4" # default flags to sort by time (eg 2025-01-03 10:04:43 +0100, hence 3 fields) additional_sort_flags=${GITFIXUPADDITIONALSORTFLAGS:-$(git config --default="" fixup.additionalSortFlags)} +format=${GITFIXUPFORMAT:-$(git config --default "%h %ai [TYPE] %s <%ae>" fixup.format)} +formatf=$(echo "$format" | sed 's/TYPE/F/g') +formatl=$(echo "$format" | sed 's/TYPE/L/g') + while test $# -gt 0; do case "$1" in -s|--squash) From d347f99275d10011d1407a7edbd433d5645f84d0 Mon Sep 17 00:00:00 2001 From: David Keijser Date: Tue, 7 Jan 2025 13:40:42 +0100 Subject: [PATCH 2/2] Simplify sort flags The flag -k2 means from field 2 to EOL rendering the rest redundant --- git-fixup | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git-fixup b/git-fixup index 850b5ea..32a588a 100755 --- a/git-fixup +++ b/git-fixup @@ -177,7 +177,7 @@ show_menu () { sort_commits () { # shellcheck disable=SC2086 - sort $sort_flags $additional_sort_flags + sort -k2 $additional_sort_flags } git_commit_args=() @@ -188,7 +188,6 @@ fixup_menu=${GITFIXUPMENU:-$(git config --default="" fixup.menu)} create_commit=${GITFIXUPCOMMIT:-$(git config --default=false --type bool fixup.commit)} base=${GITFIXUPBASE:-$(git config --default="" fixup.base)} show_all=false -sort_flags="-k2 -k3 -k4" # default flags to sort by time (eg 2025-01-03 10:04:43 +0100, hence 3 fields) additional_sort_flags=${GITFIXUPADDITIONALSORTFLAGS:-$(git config --default="" fixup.additionalSortFlags)} format=${GITFIXUPFORMAT:-$(git config --default "%h %ai [TYPE] %s <%ae>" fixup.format)} formatf=$(echo "$format" | sed 's/TYPE/F/g')