Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Last active December 26, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daij-Djan/7173749 to your computer and use it in GitHub Desktop.
Save Daij-Djan/7173749 to your computer and use it in GitHub Desktop.
Checks a folder full of subfolders if each subfolder is linked to a git repo and (in this case) if the repo is on github :)
#!/bin/bash
#config
validGitPattern1="@github.com"
echoValidRepos=0
#check git paths
for path in `ls`
do
gistfile=""
giturl=""
if [ -d "${path}" ] ; then
#check gist override
if [ -f "${path}/GIST" ] ; then
gistfile="GIST"
fi
#get git url
if [ -d "${path}/.git" ] ; then
cd "$path"
giturl=`git config --get remote.origin.url`
cd ..
fi
#check giturl
if [ -n "$giturl" ] ; then
if [[ "$giturl" == *"$validGitPattern"* ]] ; then
if [[ $echoValidRepos>0 ]] ; then
echo "ok | $path on valid git @ $giturl"
fi
else
echo "fail | $path on invalid git @ $giturl"
failedReposCounter=$[failedReposCounter+1]
fi
else
if [ -n "$gistfile" ] ; then
if [[ $echoValidRepos>0 ]] ; then
echo "ok | $path is marked as a gist"
fi
else
echo "fail | $path not even a git repo or gist"
notEvenReposCounter=$[notEvenReposCounter+1]
fi
fi
fi
done
#print counters
if [[ $failedReposCounter > 0 ]] ; then
echo "$failedReposCounter invalid git repos"
fi
if [[ $notEvenReposCounter > 0 ]] ; then
echo "$notEvenReposCounter non git repos or gists (mark using GIST file if appropriate)"
fi
@Daij-Djan
Copy link
Author

rev1 had a last minute bug that resulted from me trying to blindly optimize a thingy. I now shell scripting way too little. shouldn't have done that :D

@Daij-Djan
Copy link
Author

I changed the pattern to not only accept git@github but github.com
therefore now accepts https remotes as valid

@Daij-Djan
Copy link
Author

updated the gist to check git remotes @github but also allow marking folders with GIST files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment