Last active
October 27, 2017 14:46
-
-
Save jpeak5/920a966b3b8247ee0d7dd9ad3322cda9 to your computer and use it in GitHub Desktop.
bash script for getting the version of all git repos under $1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## thanks to | |
| # https://askubuntu.com/questions/429229/how-to-check-in-a-bash-script-if-passed-argument-is-file-or-directory | |
| # https://stackoverflow.com/questions/5311956/bash-remove-first-directory-component-from-variable-path-of-file | |
| # https://stackoverflow.com/questions/11981716/how-to-quickly-find-all-git-repos-under-a-directory | |
| # https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find | |
| # https://stackoverflow.com/questions/949314/how-to-retrieve-the-hash-for-the-current-commit-in-git | |
| # https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking | |
| # https://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repository-was-originally-cloned-fr | |
| # excellent - https://opensource.com/article/17/6/bash-parameter-expansion | |
| root=${1%%/} | |
| if [ -z $2 ] | |
| then | |
| for d in $(find $1 -type d -name '.git'); do | |
| if [ -d $d ] | |
| then | |
| cd $d/.. | |
| wkdir=$(pwd)/ | |
| echo ${wkdir#$root} $(git -C $wkdir rev-parse HEAD) $(git -C $wkdir config --get remote.origin.url) | |
| fi | |
| done | |
| else | |
| while IFS=' ' read dir rev branch remote; do | |
| git -C $root$dir fetch $branch | |
| done < $2 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment