Last active
December 6, 2018 16:11
-
-
Save shurph/317ff3aa9fc18df428c6cead8269cb15 to your computer and use it in GitHub Desktop.
Fetch all repos which are situated inside the current directory in any nested level
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
| #!/usr/bin/env sh | |
| ROOT_DIR=`pwd`; | |
| COLOR_BLUE="\e[34m" | |
| COLOR_YELLOW="\e[33m" | |
| COLOR_DEFAULT="\e[0m" | |
| if [ 'pull' = "$1" ]; then | |
| GIT_COMMAND='pull' | |
| else | |
| GIT_COMMAND='fetch' | |
| fi; | |
| echo GIT_COMMAND is "$GIT_COMMAND" | |
| run_before_git_command_DANGEROUS() | |
| { | |
| git reset --hard HEAD | |
| git checkout HEAD~1 | |
| git branch -D master | |
| git branch master origin/master | |
| } | |
| run_before_git_command() | |
| { | |
| # run_before_git_command_DANGEROUS | |
| # git checkout master | |
| } | |
| fetch_git_or_go_deeper() | |
| { | |
| cd $ROOT_DIR | |
| if [ -d "$2/$1/.git" ]; then | |
| printf "$COLOR_BLUE FETCHING REPO $1 IN $2 $COLOR_DEFAULT\n" | |
| cd $2/$1 | |
| run_before_git_command | |
| git $GIT_COMMAND --all -t | |
| else | |
| DIRECTORIES_WITH_SPACES=$(find $2/$1 -maxdepth 1 -type d -name \*' '\*) | |
| if test "$DIRECTORIES_WITH_SPACES"; then | |
| printf "$COLOR_YELLOW DIRECTORIES WITH SPACES MAY CAUSE SOME ISSUES\n" | |
| echo $DIRECTORIES_WITH_SPACES | |
| printf "$COLOR_DEFAULT\n" | |
| fi | |
| # echo find $2/$1 -maxdepth 1 -type d -name '[a-z]*' \ | |
| # -exec fetch_git_or_go_deeper {} $2/$1 \; | |
| for i in $(ls $2/$1 -1 --quoting-style=shell-escape --color=none); | |
| do | |
| if [ -d "$2/$1/$i" ]; then | |
| fetch_git_or_go_deeper "$i" "$2/$1" | |
| fi | |
| done | |
| fi | |
| cd $ROOT_DIR | |
| } | |
| fetch_git_or_go_deeper . . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment