From 6fd09a712eefce179b58a0cc2f679e24fc96bc26 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 6 May 2026 10:00:02 -0400 Subject: [PATCH] Add git_fix_author script. --- nix/configuration/roles/base/default.nix | 3 +++ .../roles/base/files/git_fix_author.bash | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 nix/configuration/roles/base/files/git_fix_author.bash diff --git a/nix/configuration/roles/base/default.nix b/nix/configuration/roles/base/default.nix index 93ba43d2..e3af336d 100644 --- a/nix/configuration/roles/base/default.nix +++ b/nix/configuration/roles/base/default.nix @@ -18,6 +18,7 @@ let git_find_merged_branches = ( patchScriptBin "git_find_merged_branches" (builtins.readFile ./files/git_find_merged_branches.bash) ); + git_fix_author = (patchScriptBin "git_fix_author" (builtins.readFile ./files/git_fix_author.bash)); alias_rga = pkgs.writeShellScriptBin "rga" '' exec ${pkgs.ripgrep}/bin/rg -uuu "''${@}" ''; @@ -66,6 +67,8 @@ in decode_jwt jq inetutils # For whois + git_find_merged_branches + git_fix_author ]; }; } diff --git a/nix/configuration/roles/base/files/git_fix_author.bash b/nix/configuration/roles/base/files/git_fix_author.bash new file mode 100644 index 00000000..55c05db2 --- /dev/null +++ b/nix/configuration/roles/base/files/git_fix_author.bash @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +git filter-branch --env-filter ' +WRONG_EMAIL="old@email.foo" +NEW_NAME="New Name" +NEW_EMAIL="new@email.bar" + +if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ] +then + export GIT_COMMITTER_NAME="$NEW_NAME" + export GIT_COMMITTER_EMAIL="$NEW_EMAIL" +fi +if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ] +then + export GIT_AUTHOR_NAME="$NEW_NAME" + export GIT_AUTHOR_EMAIL="$NEW_EMAIL" +fi +' --tag-name-filter cat --commit-filter 'git commit-tree -S "$@";' -- --branches --tags