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