feat(user/git): add interactive fixup

This commit is contained in:
Patrick 2024-07-27 19:49:13 +02:00
parent 377239650e
commit 1048dbcb77
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F

View file

@ -1,4 +1,30 @@
{ pkgs, ... }: { pkgs, lib, ... }:
let
gf = lib.getExe (
pkgs.writeShellApplication {
name = "git-fixup-fzf";
runtimeInputs = [
pkgs.fzf
pkgs.gnugrep
];
text = ''
if ! commit=$(git log --graph --color=always --format="%C(auto)%h%d %s %C(reset)%C(bold)%cr" "$@" \
| fzf --ansi --multi --no-sort --reverse --print-query --expect=ctrl-d --toggle-sort=\`); then
echo aborted
exit 0
fi
sha=$(grep -o '^[^a-z0-9]*[a-z0-9]\{7\}[a-z0-9]*' <<< "$commit" | grep -o '[a-z0-9]\{7\}[a-z0-9]*')
if [[ -z "$sha" ]]; then
echo "Found no checksum for selected commit. Aborting."
exit 1
fi
git fixup "$sha" "$@"
'';
}
);
in
{ {
programs.git = { programs.git = {
enable = true; enable = true;
@ -11,6 +37,7 @@
p = "push"; p = "push";
rebase = "rebase --gpg-sign"; rebase = "rebase --gpg-sign";
fixup = ''!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ''${@:2} && EDITOR=true git rebase -i --gpg-sign --autostash --autosquash $TARGET^; }; f''; fixup = ''!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ''${@:2} && EDITOR=true git rebase -i --gpg-sign --autostash --autosquash $TARGET^; }; f'';
f = "!${gf}";
crm = ''!git commit -v -S --edit --file "$(git rev-parse --git-dir)"/COMMIT_EDITMSG''; crm = ''!git commit -v -S --edit --file "$(git rev-parse --git-dir)"/COMMIT_EDITMSG'';
}; };
extraConfig = { extraConfig = {