Git/GCP Cloud Source
< Git
Jump to navigation
Jump to search
Download all repos across all projects:
#!/bin/bash #GCP_USERNAME=username@acme.com GCP_USERNAME=$(gcloud info --format=yaml | grep account: | head -1 | tr -s " " | cut -f3 -d" " | tr -d " ") GCP_PROJECTS_IDS=($(gcloud projects list | tail +2 | tr -s " " | cut -f1 -d " ")) echo -e "[INFO] GCP_PROJECTS: ${#GCP_PROJECTS_IDS[@]}\n${GCP_PROJECTS_IDS[@]}" for PROJECT in ${GCP_PROJECTS_IDS[@]}; do # loop over projects # discover repos in a project echo "[INFO] ---" echo -e "[INFO] Project: $PROJECT" REPOS=($(gcloud source repos list --project $PROJECT | cut -f1 -d" " | tail +2)) if ((! ${#REPOS[@]})); then echo "[INFO] No repositories found."; continue; fi echo -e "[INFO] Found following repositories: ${#REPOS[@]}\n${REPOS[@]}" [ -d $PROJECT ] || mkdir $PROJECT # create a directory per project cd $PROJECT for REPO in ${REPOS[@]}; do # loop over repositories if [ -d $REPO ]; then echo "[INFO] Update repository: $PROJECT/$REPO" cd $REPO; git pull; cd - else echo "[INFO] git clone ssh://${GCP_USERNAME}@source.developers.google.com:2022/p/${PROJECT}/r/${REPO}" git clone ssh://${GCP_USERNAME}@source.developers.google.com:2022/p/${PROJECT}/r/${REPO} fi done cd .. # return to root directory, level up from a project directory done
Note: If any cloning get stuck in Resolving deltas: 100% (46222/46222), done
, do:
Ctrl+C
, cd $REPO
, git fetch
to fetch branch information from the remote repository, git checkout master
or any other branch