#!/bin/bash # git-affecting # @link https://gist.github.com/shadowhand/130dbcf6d9b01877797b # @author shadowhand https://github.com/shadowhand # @license MIT # # installation: # save this file as git-affecting somewhere in your $PATH # make it executable: chmod +x git-affecting # # optional: # git config --global alias.af '! git affecting' # # usage: # git affecting # see all the branches that are modifying the file # ??? # profit # # enjoy! # usage() { echo "usage: git affecting [ ...]" } # changelog # # 0.0.1 # - initial release # version() { echo "switchbranch v0.0.1" } _affecting() { # First get all branches that are known to the origin local branches=$(git branch -a | grep "remotes/origin/" | grep -v "master") local found=0 local GREEN="\033[0;32m" local BLANK="\033[0m" if [ -z "$1" ]; then usage exit 1 fi for file in $@; do if [ $found -gt 0 ]; then echo " " # add newline from previous run fi found=0 for branch in $branches; do git diff --name-only $branch $(git merge-base $branch master) | grep "$file" 2>&1 >/dev/null if [ $? -eq 0 ]; then if [ $found -eq 0 ]; then found=1 echo -e "File $GREEN$file$BLANK changed in:" fi echo "- $branch" | sed -e 's/remotes\/origin\///' fi done done exit 0 } main() { local command="$1" case $command in "version") version;; *) _affecting "$@";; esac } main "$@"