Skip to content

Instantly share code, notes, and snippets.

@nabsha
Last active September 7, 2017 05:17
Show Gist options
  • Save nabsha/d164e05787acf9890939f6090816ffeb to your computer and use it in GitHub Desktop.
Save nabsha/d164e05787acf9890939f6090816ffeb to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# python get-all-stash-repos.py [host] [project] [user] [password] [target-root-dir]
import sys
import os
import stashy
import git
import argparse
import getpass
parser = argparse.ArgumentParser(description='get all repositories from stash')
parser.add_argument('-H','--host', help='stash host', required=True)
parser.add_argument('-p','--project', help='stash project', required=True)
parser.add_argument('-u','--user', help='stash user', required=True)
parser.add_argument('-d','--directory', help='output directory', required=True)
args = vars(parser.parse_args())
host = args['host']
project = args['project']
user = args['user']
directory = args['directory']
if directory.endswith('/') != True:
directory = directory + '/'
if not os.path.exists(directory):
os.makedirs(directory)
print ("Cloning repositories from " + host + " for " + user)
password = getpass.getpass()
stash = stashy.connect(host, user, password)
for repo in stash.projects[project].repos.list():
for url in repo["links"]["clone"]:
if (url["name"] == "http"):
if not os.path.exists(directory + repo["name"]):
print ("Cloning " + url["href"] + " to " + directory + repo["name"])
git.Git().clone(url["href"], directory + repo["name"])
else:
print ("Directory already exists: " + directory + repo["name"] + ", skipping")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment