From fa14170d3b227b8a4457263ac959fe035b227efb Mon Sep 17 00:00:00 2001 From: Guy Kisel Date: Sun, 24 Feb 2019 13:03:57 -0800 Subject: [PATCH 1/2] wip clone dotfile repos --- inlineplz/util/git.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/inlineplz/util/git.py b/inlineplz/util/git.py index ddacb1e6..9cd3a7c4 100644 --- a/inlineplz/util/git.py +++ b/inlineplz/util/git.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +import os import subprocess +import tempfile def current_sha(): @@ -100,3 +102,42 @@ def command(*args): return ( subprocess.check_output(git_command).strip().decode("utf-8", errors="replace") ) + + +def clone(url, dir=None, token=None, ref=None): + if not dir: + dir = os.getcwd() + if token: + # https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth + url = url.replace('https://', 'https://{}@'.format(token)) + print('Cloning: {}'.format(url)) + try: + os.makedirs(dir) + except OSError: + pass + try: + subprocess.check_call( + ['git', 'init'], + cwd=dir + ) + + pull_cmd = ['git', 'pull', url] + if ref: + pull_cmd.append(ref) + subprocess.check_call( + pull_cmd, + cwd=dir + ) + return True + except subprocess.CalledProcessError: + return False + + +def clone_dotfiles(url, org, token=None): + dotfile_dir = tempfile.mkdtemp() + for repo in ["dotfiles", ".dotfiles", ".github"]: + clone_url = '/'.join([url, org, repo]) + '.git' + print('Cloning: {}'.format(clone_url)) + dotfile_path = os.path.join(dotfile_dir, repo) + if clone(clone_url, dotfile_path, token): + return dotfile_path From 97a18bddac5ea412d2035ff5b98f7a39df633625 Mon Sep 17 00:00:00 2001 From: guykisel Date: Tue, 26 Feb 2019 00:20:23 +0000 Subject: [PATCH 2/2] Autofix by inline-plz --- inlineplz/util/git.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/inlineplz/util/git.py b/inlineplz/util/git.py index 9cd3a7c4..538404b1 100644 --- a/inlineplz/util/git.py +++ b/inlineplz/util/git.py @@ -109,25 +109,19 @@ def clone(url, dir=None, token=None, ref=None): dir = os.getcwd() if token: # https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth - url = url.replace('https://', 'https://{}@'.format(token)) - print('Cloning: {}'.format(url)) + url = url.replace("https://", "https://{}@".format(token)) + print("Cloning: {}".format(url)) try: os.makedirs(dir) except OSError: pass try: - subprocess.check_call( - ['git', 'init'], - cwd=dir - ) + subprocess.check_call(["git", "init"], cwd=dir) - pull_cmd = ['git', 'pull', url] + pull_cmd = ["git", "pull", url] if ref: pull_cmd.append(ref) - subprocess.check_call( - pull_cmd, - cwd=dir - ) + subprocess.check_call(pull_cmd, cwd=dir) return True except subprocess.CalledProcessError: return False @@ -136,8 +130,8 @@ def clone(url, dir=None, token=None, ref=None): def clone_dotfiles(url, org, token=None): dotfile_dir = tempfile.mkdtemp() for repo in ["dotfiles", ".dotfiles", ".github"]: - clone_url = '/'.join([url, org, repo]) + '.git' - print('Cloning: {}'.format(clone_url)) + clone_url = "/".join([url, org, repo]) + ".git" + print("Cloning: {}".format(clone_url)) dotfile_path = os.path.join(dotfile_dir, repo) if clone(clone_url, dotfile_path, token): return dotfile_path