From 3be989de7d5c930752a06e2fd5623c4637eaf7da Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Wed, 10 Apr 2024 11:42:01 +0300 Subject: [PATCH] Git : Make git_resign specify commit count. --- module/common/bash/module/Git.nix | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/module/common/bash/module/Git.nix b/module/common/bash/module/Git.nix index b3f9a8d..49bae66 100644 --- a/module/common/bash/module/Git.nix +++ b/module/common/bash/module/Git.nix @@ -131,12 +131,12 @@ function gr() { local base="''${1}" - # rebase last 2 commits by default. + # Rebase last 2 commits by default. if [[ "''${base}" = "" ]]; then base="2" fi - # if 0, rebase from root. else from specified base. + # If 0, rebase from root. else from specified base. if [[ "''${base}" = "0" ]]; then git rebase -i --root else @@ -195,9 +195,22 @@ open "''${url}" } - # Resign all the old commits. + # Resign the old commits. 0 to resign from root. + # Usage: git_resign [COMMIT_COUNT] function git_resign() { - git rebase --exec 'git commit --amend --no-edit -n -S' -i --root + local base="''${1}" + + # Resign last commit by default. + if [[ "''${base}" = "" ]]; then + base="1" + fi + + # If 0, rebase from root. else from specified base. + if [[ "''${base}" = "0" ]]; then + git rebase --exec 'git commit --amend --no-edit -n -S' -i --root + else + git rebase --exec 'git commit --amend --no-edit -n -S' -i HEAD~''${base} + fi } # Show current branch.