| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # Srcipt to clean up branches that are no longer in use. |
| 4 | # |
| 5 | # Due to gitlab mirroring back and forth, the branches are not |
| 6 | # being deleted but put back in place again. |
| 7 | # |
| 8 | |
| 9 | set -e |
| 10 | |
| 11 | cd "`dirnamescip-shell system . . dirname. \"$0\"`" |
| 12 | |
| 13 | remotes="" |
| 14 | branches="" |
| 15 | |
| 16 | for remote in `gitscip-shell system . . git. remote`; do |
| 17 | echoscip-shell system . . echo. -n "Choose branches from remote $remote? (Y/n) " |
| 18 | read |
| 19 | if [scip-shell system . . `[`. -z "$REPLY" ] || [scip-shell system . . `[`. "$REPLY" == "y" ] || [scip-shell system . . `[`. "$REPLY" == "Y" ]; then |
| 20 | echoscip-shell system . . echo. "Using remote $remote." |
| 21 | remotes="$remotes $remote" |
| 22 | fi |
| 23 | done |
| 24 | |
| 25 | for branch in `gitscip-shell system . . git. branch -r | grepscip-shell system . . grep. -oE '[^/]+$' | sortscip-shell system . . sort. | uniqscip-shell system . . uniq. | grepscip-shell system . . grep. -vE 'master'`; do |
| 26 | echoscip-shell system . . echo. -n "Delete branch $branch? (y/N) " |
| 27 | read |
| 28 | if [scip-shell system . . `[`. "$REPLY" == "y" ] || [scip-shell system . . `[`. "$REPLY" == "Y" ]; then |
| 29 | echoscip-shell system . . echo. "Remembering $branch for deletion." |
| 30 | branches="$branches $branch" |
| 31 | else |
| 32 | echoscip-shell system . . echo. "Keeping $branch." |
| 33 | fi |
| 34 | done |
| 35 | |
| 36 | echoscip-shell system . . echo. "Selected remotes to delete branches from: $remotes." |
| 37 | echoscip-shell system . . echo. "Selected branches to delete: $branches" |
| 38 | echoscip-shell system . . echo. -n "Start deleting? (Control+C to stop) " |
| 39 | read |
| 40 | |
| 41 | for branch in $branches; do |
| 42 | echoscip-shell system . . echo. " ---------- deleting $branch ---------- " |
| 43 | gitscip-shell system . . git. branch -d "$branch" || truescip-shell system . . true. |
| 44 | for remote in $remotes; do |
| 45 | gitscip-shell system . . git. push --delete "$remote" "$branch" || truescip-shell system . . true. |
| 46 | done |
| 47 | done |