File: git-delete-squashed-branches

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (28 lines) | stat: -rwxr-xr-x 716 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash

set -euo pipefail

proceed=false
if [[ $# -gt 0 && ("$1" == "--proceed" || "$1" == "-p") ]]; then
    proceed=true
    shift
fi

if [[ $# -eq 0 ]]; then
  targetBranch=$(git rev-parse --abbrev-ref HEAD)
else
  targetBranch=$1
  git checkout "$targetBranch"
fi

git for-each-ref refs/heads/ "--format=%(refname:short)" | while read -r branch; do
    mergeBase=$(git merge-base "$targetBranch" "$branch")

    if [[ $(git cherry "$targetBranch" "$(git commit-tree "$(git rev-parse "$branch^{tree}")" -p "$mergeBase" -m _)") == "-"* ]]; then
        if [[ $proceed == true ]]; then
            git branch -D "$branch" || true
        else
            git branch -D "$branch"
        fi
    fi
done