Skip to content

Instantly share code, notes, and snippets.

@h4
Created July 3, 2018 16:49
Show Gist options
  • Save h4/c73943fe53c97c722cb9befbd4e4b654 to your computer and use it in GitHub Desktop.
Save h4/c73943fe53c97c722cb9befbd4e4b654 to your computer and use it in GitHub Desktop.
Find substring in git bare repos
#!/usr/bin/env bash
set -e
ROOT=$1
PATTERN=$2
walkdir() {
CUR_DIR=$1
pushd $CUR_DIR > /dev/null
for DIR in $(ls $CUR_DIR)
do
if [[ "$DIR" == *.git ]]
then
if ! [[ "$DIR" == *.wiki.git ]]
then
find_pattern $(realpath "$DIR")
fi
else
walkdir "$(realpath $DIR)"
fi
done
popd > /dev/null
}
find_pattern() {
CUR_REPO=$1
pushd $CUR_REPO > /dev/null
exit_code=0
git grep -e "$PATTERN" HEAD 2>/dev/null || exit_code=$?
if [ "$exit_code" -eq "0" ]
then
pwd
printf "\n\n"
fi
popd > /dev/null
}
walkdir "$ROOT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment