From d9c4f824d2cf6d3768a618b044360c7859b86c58 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 6 May 2026 09:56:18 -0400 Subject: [PATCH] Add git_find_merged_branches script. --- nix/configuration/roles/base/default.nix | 3 +++ .../roles/base/files/git_find_merged_branches.bash | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 nix/configuration/roles/base/files/git_find_merged_branches.bash diff --git a/nix/configuration/roles/base/default.nix b/nix/configuration/roles/base/default.nix index b42cfed2..93ba43d2 100644 --- a/nix/configuration/roles/base/default.nix +++ b/nix/configuration/roles/base/default.nix @@ -15,6 +15,9 @@ let patchScriptBin "cleanup_temporary_files" (builtins.readFile ./files/cleanup_temporary_files.bash) ); decode_jwt = (patchScriptBin "decode_jwt" (builtins.readFile ./files/decode_jwt.bash)); + git_find_merged_branches = ( + patchScriptBin "git_find_merged_branches" (builtins.readFile ./files/git_find_merged_branches.bash) + ); alias_rga = pkgs.writeShellScriptBin "rga" '' exec ${pkgs.ripgrep}/bin/rg -uuu "''${@}" ''; diff --git a/nix/configuration/roles/base/files/git_find_merged_branches.bash b/nix/configuration/roles/base/files/git_find_merged_branches.bash new file mode 100644 index 00000000..f794b857 --- /dev/null +++ b/nix/configuration/roles/base/files/git_find_merged_branches.bash @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# +# Find local branches that have been merged +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +: ${MAIN_BRANCH:="main"} + +git checkout -q ${MAIN_BRANCH} && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base ${MAIN_BRANCH} $branch) && [[ $(git cherry ${MAIN_BRANCH} $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && echo "$branch"; done