From e0a957e448c36add8a6145180dc378b59bcb2ab4 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 14 Nov 2024 14:03:36 +0100 Subject: [PATCH] home/git: add fixup-interactive script --- home/programs/git/default.nix | 6 ++++++ .../git/scripts/git-fixup-interactive.sh | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 home/programs/git/scripts/git-fixup-interactive.sh diff --git a/home/programs/git/default.nix b/home/programs/git/default.nix index c91267c..26ea8b5 100644 --- a/home/programs/git/default.nix +++ b/home/programs/git/default.nix @@ -52,6 +52,7 @@ in authors = "shortlog --summary --numbered --email"; si = "switch-interactive"; ff = "fixup-fixup"; + fi = "fixup-interactive"; rf = "rebase-fixups"; pp = "post-pr"; subs = "submodule update --init --recursive"; @@ -335,6 +336,11 @@ in runtimeInputs = with pkgs; [ cfg.package gnused ]; text = lib.fileContents ./scripts/git-rebase-fixups.sh; }) + (pkgs.writeShellApplication { + name = "git-fixup-interactive"; + runtimeInputs = with pkgs; [ cfg.package gnused gnugrep fzf ]; + text = lib.fileContents ./scripts/git-fixup-interactive.sh; + }) (pkgs.writeShellApplication { name = "git-switch-interactive"; runtimeInputs = with pkgs; [ cfg.package fzf gnused coreutils ]; diff --git a/home/programs/git/scripts/git-fixup-interactive.sh b/home/programs/git/scripts/git-fixup-interactive.sh new file mode 100644 index 0000000..018df6d --- /dev/null +++ b/home/programs/git/scripts/git-fixup-interactive.sh @@ -0,0 +1,18 @@ +if [ -n "${1:-}" ]; then + TARGET_BRANCH="$1" + shift +else + TARGET_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') +fi + +FORK_POINT=$(git merge-base --fork-point "$TARGET_BRANCH") + +COMMITS_SINCE_FORK_POINT=$(git log --format=format:'%s' "$FORK_POINT"..HEAD | grep -v -E '^fixup!') + +RESULT=$(fzf <<<"$COMMITS_SINCE_FORK_POINT") + +if [ "$RESULT" == "" ]; then + echo "Doing nothing..." +else + git commit -m "fixup! $RESULT" "$@" +fi