From 84c9562bfc581732cb7f96a7bf4523f926bbb552 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 13 Nov 2024 16:57:00 +0100 Subject: [PATCH] home/git: add rebase-fixups script --- home/programs/git/default.nix | 6 ++++++ home/programs/git/scripts/git-rebase-fixups.sh | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 home/programs/git/scripts/git-rebase-fixups.sh diff --git a/home/programs/git/default.nix b/home/programs/git/default.nix index 6e8001e..8f2f212 100644 --- a/home/programs/git/default.nix +++ b/home/programs/git/default.nix @@ -54,6 +54,7 @@ in authors = "shortlog --summary --numbered --email"; si = "switch-interactive"; ff = "fixup-fixup"; + rf = "rebase-fixups"; pp = "post-pr"; subs = "submodule update --init --recursive"; rebase-author = "rebase -i -x \"git commit --amend --reset-author -CHEAD\""; @@ -277,6 +278,11 @@ in runtimeInputs = with pkgs; [ cfg.package ]; text = lib.fileContents ./scripts/git-fixup-fixup.sh; }) + (pkgs.writeShellApplication { + name = "git-rebase-fixups"; + runtimeInputs = with pkgs; [ cfg.package gnused ]; + text = lib.fileContents ./scripts/git-rebase-fixups.sh; + }) (pkgs.writeShellApplication { name = "git-switch-interactive"; runtimeInputs = with pkgs; [ cfg.package fzf gnused coreutils ]; diff --git a/home/programs/git/scripts/git-rebase-fixups.sh b/home/programs/git/scripts/git-rebase-fixups.sh new file mode 100644 index 0000000..1f4f09d --- /dev/null +++ b/home/programs/git/scripts/git-rebase-fixups.sh @@ -0,0 +1,10 @@ +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") + +git rebase "$FORK_POINT" --autosquash "$@"