summaryrefslogtreecommitdiff
path: root/src/Git:Branch_Author_List.ascii
blob: 2a46d45192d85fe20260c2d14768099bd5052e29 (plain)
    1 Git:Branch Author List
    2 ======================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 
    7 == {doctitle}
    8 
    9 Whether your team uses the long-running, topic, or any other multi-branch
   10 https://git-scm.herokuapp.com/book/en/v2/Git-Branching-Branching-Workflows[branching
   11 workflows], you usually end up with many server-side "abandonded" branches that
   12 haven't been commited to in a while, especially when the team is relatively
   13 agile. While a cluttered server-side branch set it isn't always a pressing
   14 issue, the difficulty in cleanup can make it be a long-standing issue; one that
   15 gets worse and worse as time goes by.
   16 
   17 Enter, the *git-branch-authors.sh* script.
   18 
   19 I wrote this script because my team has the problem I described above.  To
   20 preface the source code though, git doesn't track _who_ created a branch. It
   21 just tracks at which commit reference the branch was forked from its parent,
   22 which means we can't actually tell _who_ created a given branch. However, since
   23 a branch is usually commited to by its creator, we can make an educated guess
   24 by using the name of the person who commited most recently. At the very least,
   25 the most recent author will give a point of contact to help find out
   26 information about the branch.
   27 
   28 ----
   29 #!/usr/bin/env bash
   30 
   31 # Verify we're inside a git repo
   32 git status 2>/dev/null 1>/dev/null
   33 if [[ $? != 0 ]]; then
   34   echo "Error: '$(pwd)' is not a epository."
   35   exit 1
   36 fi
   37 
   38 # Set the column headers
   39 out='Unix Timestamp~Branch~Timestamp~Commit~Author~Relative Time'
   40 
   41 # Parse the branches
   42 for i in $(git branch -r | grep -v HEAD); do
   43   format="unix:%at~${i}~%ai~%h~%an <%ae>~commited %ar"
   44   cmd=$(git show "${i}" --format="${format}" | head -n 1)
   45   out=${out}'\n'${cmd}
   46 done
   47 
   48 # Output the goodness
   49 echo -e ${out} | sort -r -n | column -s '~' -t
   50 
   51 ----
   52 
   53 To use this, simply save it to your *~/bin* directory (ensure your PATH
   54 variable has \~/bin in it or that won't work) and +chmod \+x
   55 ~/bin/git-branch-authors.sh+.
   56 
   57 Category:Bash
   58 Category:Scripts
   59 Category:Git
   60 
   61 
   62 // vim: set syntax=asciidoc:

Generated by cgit