Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ script into your `$PATH` and `$fpath` respectively.

```
git-fixup [-s|--squash] [-f|--fixup] [-a|--amend] [-c|--commit] [--no-verify]
[--rebase] [-b|--base <rev>] [<ref>]
[--rebase] [-b|--base <rev>] [-r|--reverse] [<ref>]
```

For this tool to make any sense you should enable the `rebase.autosquash`
Expand Down Expand Up @@ -143,6 +143,10 @@ If omitted, the default base commit is resolved in the following order:
4. Finally, the root commit (i.e. full history) if nothing of the above is
satisfied.

### --reverse

Commits are sorted by time. `-r` reverses the sort order.

## Configuration

`git-fixup` uses configuration from the ENVIRONMENT or from `git config`
Expand Down Expand Up @@ -193,6 +197,20 @@ a simple [default menu](the-default-menu) will be used.
See [External menu](#external-menu) for more details and a more advanced
example.

### fixup.additionalSortFlags

Or `GITFIXUPADDITIONALSORTFLAGS`

Sets the flags that are passed to sort in addition to the default sort flags
that enable sorting by time.

For example,

```bash
# Always sort the commits by time reversed
$ git config --global fixup.additionalSortFlags '-r'
```

## Tab completion

Tab completion for zsh/fish is implemented. The suggestions for the tab completion
Expand Down
18 changes: 14 additions & 4 deletions git-fixup
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ no-rebase Don't do a rebase after commit
n,no-verify Bypass the pre-commit and commit-msg hooks
b,base=rev Use <rev> as base of the revision range for the search
A,all Show all candidates
r,reverse Reverse the sort
"
# shellcheck disable=SC2034
SUBDIRECTORY_OK=yes
Expand Down Expand Up @@ -69,7 +70,7 @@ print_sha () {
local sha=$1
local type=$2

git --no-pager log --format="%H [$type] %s <%ae>" -n 1 "$sha"
git --no-pager log --format="%h %ai [$type] %s <%ae>" -n 1 "$sha"
}

# Call git commit
Expand Down Expand Up @@ -164,6 +165,11 @@ show_menu () {
fi
}

sort_commits () {
# shellcheck disable=SC2086
sort $sort_flags $additional_sort_flags
}

git_commit_args=()
target=
op=${GITFIXUPACTION:-$(git config --default=fixup fixup.action)}
Expand All @@ -172,7 +178,8 @@ 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)}
while test $# -gt 0; do
case "$1" in
-s|--squash)
Expand Down Expand Up @@ -209,6 +216,9 @@ while test $# -gt 0; do
-A|--all)
show_all=true
;;
-r|--reverse)
additional_sort_flags="-r"
;;
--)
shift
break
Expand Down Expand Up @@ -264,7 +274,7 @@ else
fi

if test "$create_commit" = "true"; then
target=$(print_candidates | show_menu)
target=$(print_candidates | sort_commits | show_menu)
if test -z "$target"; then
exit
fi
Expand All @@ -273,5 +283,5 @@ if test "$create_commit" = "true"; then
call_rebase "${target%% *}"
fi
else
print_candidates
print_candidates | sort_commits
fi
Loading