Skip to content

Instantly share code, notes, and snippets.

@shurph
Last active December 6, 2018 16:11
Show Gist options
  • Save shurph/317ff3aa9fc18df428c6cead8269cb15 to your computer and use it in GitHub Desktop.
Save shurph/317ff3aa9fc18df428c6cead8269cb15 to your computer and use it in GitHub Desktop.

Revisions

  1. shurph revised this gist Dec 6, 2018. 1 changed file with 28 additions and 2 deletions.
    30 changes: 28 additions & 2 deletions fetch-all-repos.sh
    Original file line number Diff line number Diff line change
    @@ -5,13 +5,39 @@ 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
    git fetch --all -t
    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
    @@ -31,4 +57,4 @@ fetch_git_or_go_deeper()
    cd $ROOT_DIR
    }

    fetch_git_or_go_deeper . .
    fetch_git_or_go_deeper . .
  2. shurph created this gist Aug 24, 2018.
    34 changes: 34 additions & 0 deletions fetch-all-repos.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/usr/bin/env sh

    ROOT_DIR=`pwd`;
    COLOR_BLUE="\e[34m"
    COLOR_YELLOW="\e[33m"
    COLOR_DEFAULT="\e[0m"

    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
    git fetch --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 . .