Skip to content

Instantly share code, notes, and snippets.

@pandada8
Last active May 27, 2016 17:02
Show Gist options
  • Save pandada8/4cb63439c3ea295b841dd84fd6bce149 to your computer and use it in GitHub Desktop.
Save pandada8/4cb63439c3ea295b841dd84fd6bce149 to your computer and use it in GitHub Desktop.
git clone helper
#!/bin/env python
import os
import sys
from urllib.parse import urlsplit
import subprocess
os.chdir(os.path.expanduser("~/repo/"))
def clone(url, folder):
os.makedirs(folder, exist_ok=True)
if os.listdir(folder):
print("{} is not empty, not clone.".format(folder))
return
subprocess.run(["git", "clone", url, folder])
print("new project cloned at", "~/repo/{}".format(folder))
for i in sys.argv[1:]:
print("deal with {}".format(i))
if i.startswith("http"):
# is a url and try to clone
folder = urlsplit(i).path[1:].rstrip(".git")
clone(i, folder)
elif i.startswith("git@"):
# a ssh protocol
folder = i.split(":")[-1].rstrip(".git")
clone(i, folder)
else:
clone("https://github.com/{}.git".format(i), i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment