From 49f0a457e5255c05b3f9c80fce46c845214ae209 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 13 Nov 2024 16:32:36 +0100 Subject: [PATCH] home/git: add git-fixup-fixup script --- home/programs/git/default.nix | 6 ++++++ home/programs/git/scripts/git-fixup-fixup.sh | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 home/programs/git/scripts/git-fixup-fixup.sh diff --git a/home/programs/git/default.nix b/home/programs/git/default.nix index 716c4bc..61df1b9 100644 --- a/home/programs/git/default.nix +++ b/home/programs/git/default.nix @@ -53,6 +53,7 @@ in forcepush = "push --force-with-lease --force-if-includes"; authors = "shortlog --summary --numbered --email"; si = "switch-interactive"; + ff = "fixup-fixup"; subs = "submodule update --init --recursive"; rebase-author = "rebase -i -x \"git commit --amend --reset-author -CHEAD\""; git = "!git"; @@ -270,6 +271,11 @@ in (builtins.replaceStrings ["hours" "tcommit"] ["minutes" "tmcommit"]) ]; }) + (pkgs.writeShellApplication { + name = "git-fixup-fixup"; + runtimeInputs = with pkgs; [ cfg.package ]; + text = lib.fileContents ./scripts/git-fixup-fixup.sh; + }) (pkgs.writeShellApplication { name = "git-switch-interactive"; runtimeInputs = with pkgs; [ cfg.package fzf gnused coreutils ]; diff --git a/home/programs/git/scripts/git-fixup-fixup.sh b/home/programs/git/scripts/git-fixup-fixup.sh new file mode 100644 index 0000000..464da15 --- /dev/null +++ b/home/programs/git/scripts/git-fixup-fixup.sh @@ -0,0 +1,14 @@ +if [ -n "${1:-}" ]; then + TARGET_COMMIT="$1" + shift +else + TARGET_COMMIT="HEAD" +fi + +COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' "$TARGET_COMMIT") + +if [[ $COMMIT_MESSAGE =~ ^fixup!* ]]; then + git commit -m "$COMMIT_MESSAGE" "$@" +else + git commit --fixup "$TARGET_COMMIT" "$@" +fi