Last active
September 22, 2015 11:05
-
-
Save byrnedo/287ab054f642dff98a1d to your computer and use it in GitHub Desktop.
Clone every repo in an Atlassian Stash project. Must run with env variables STASH_USER and STASH_PASSWORD set. Must also change url and git url.
This file contains 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 | |
if [ $# -lt 1 ] | |
then | |
echo >&2 Must give project code as argument | |
exit 1 | |
fi | |
string_project=$1 | |
#CHANGEME | |
string_url=https://stash.url.com | |
#CHANGEME | |
string_git_url=ssh://git@stash.giturl.com/ | |
string_user=${STASH_USER} | |
string_pass=${STASH_PASSWORD} | |
string_repos=$(curl -s -m 15 -u "${string_user}:${string_pass}" ${string_url}/rest/api/1.0/projects/${string_project}/repos|python -m json.tool|grep cloneUrl|awk '{print $2}'|sed 's/"\(.*\)",/\1/') | |
if [ ! -d ${string_project} ] | |
then | |
mkdir ${string_project} | |
fi | |
cd ${string_project} || exit 1 | |
for string_uri in ${string_repos} | |
do | |
string_dir=$(basename ${string_uri}|sed 's/\.git$//') | |
echo ${string_dir} | |
if [ ! -d ${string_dir} ] | |
then | |
git clone ${string_git_url}/${string_project}/${string_dir}.git | |
else | |
cd ${string_dir} && git fetch origin | |
cd .. | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment