#!/bin/sh # Copyright (C) 2021 Denis 'GNUtoo' Carikli # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . usage() { echo "Usage: $0 " exit 1 } print_header() { string="$1" str_len="$(expr $(echo ${string} | wc -c) - 1)" spaces=1 printf "%s%${spaces}s" "${string}" printf "%$(expr 80 - ${str_len} - ${spaces})s\n" | tr " " "-" } print_footer() { # Prints 80 '-' printf "%80s\n" | tr " " "-" } grep_all_tags() { repository="$1" patterns="$2" for tag in $(git -C ${repository} tag) ; do print_header "tag: ${tag}" git -C "${repository}" grep "${patterns}" print_footer done } grep_all_branches() { repository="$1" remote="$2" patterns="$3" for branch in $(git -C "${repository}" branch -a --list "${remote}/*" | \ sed "s#^ remotes/${remote}/##" | \ grep -v ".* \-> .*") ; do print_header "branch: ${branch}" git -C "${repository}" grep "${patterns}" "${remote}/${branch}" print_footer done } if [ $# -ne 3 ] ; then usage fi repository="$1" # Force the user to use a remote to avoid accidentaly thinking # that everything is ok if the origin remote isn't the same. remote="$2" patterns="$3" grep_all_tags "${repository}" "${patterns}" grep_all_branches "${repository}" "${remote}" "${patterns}"