ACTIN-3460: Add script to clean git branches#140
Conversation
nedleitch
left a comment
There was a problem hiding this comment.
Seems fine, I might call it git-clean-stale-branches or something similarly more-descriptive.
| #!/usr/bin/env bash | ||
|
|
||
| git fetch --prune | ||
| mapfile -t MERGED_DELETED_BRANCHES < <(git branch -vv | grep ': gone]' | awk '{print $1}') |
There was a problem hiding this comment.
Nit here, I don't think you need the <(...) construct, which presents a file descriptor for the given command output, because mapfile is meant to take stdin. In fact I thought you had to specify -u for that?
While this may (or may not...) work, I'd expect to see either:
git branch -vv | grep ': gone]' | awk '{print $1}' | mapfile -t MERGED_DELETED_BRANCHES
or
mapfile -t MERGED_DELETED_BRANCHES < $(git branch ...)
There was a problem hiding this comment.
Seems I can't use mapfile -t MERGED_DELETED_BRANCHES < $(git branch ...) since < to redirect to stdin expects a file descriptor, and I can't use git branch -vv | grep ': gone]' | awk '{print $1}' | mapfile -t MERGED_DELETED_BRANCHES because it scopes the MERGED_DELETED_BRANCHES variable to the pipeline. I could do mapfile -t MERGED_DELETED_BRANCHES <<< $(git branch ...) but it doesn't feel much better than what's there already.
There was a problem hiding this comment.
Fair enough. Maybe the GNU version behaves differently. Still fine to merge :)
Wrote this to delete stale branches on my local git, added it to scripts because I felt it might be useful to someone else.