Created
August 21, 2015 02:34
-
-
Save djhaskin987/0bd55475dfad9d2c3ea7 to your computer and use it in GitHub Desktop.
Clone a git repo in an organized, convenient fashion
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
#!/usr/bin/python | |
from __future__ import unicode_literals | |
from __future__ import print_function | |
from __future__ import absolute_import | |
from __future__ import division | |
import giturlparse | |
import os | |
import subprocess | |
import argparse | |
import sys | |
home = os.path.expanduser("~") | |
arg_parser = argparse.ArgumentParser(prog=sys.argv[0], | |
description="Clone git repos sanely and organizedly.") | |
arg_parser.add_argument("url", type=str, help="URL to git repository") | |
arg_parser.add_argument("--workspace", type=str, | |
help="""Folder where all the repos go""", | |
default=os.path.join(home,"Workspace","git")) | |
args = arg_parser.parse_args(sys.argv[1:]) | |
url_info = giturlparse.parse(args.url) | |
location = os.path.abspath( | |
os.path.join( | |
args.workspace, | |
url_info.host, | |
url_info.owner, | |
url_info.repo | |
) | |
) | |
if not os.path.exists(location): | |
os.makedirs(location) | |
subprocess.check_call(["git", "clone", args.url, location]) | |
if os.environ.get('GIT_GUITOOL'): | |
os.chdir(location) | |
subprocess.check_call(["git", "cola"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment