Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions inlineplz/util/git.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

import os
import subprocess
import tempfile


def current_sha():
Expand Down Expand Up @@ -100,3 +102,36 @@ def command(*args):
return (
subprocess.check_output(git_command).strip().decode("utf-8", errors="replace")
)


def clone(url, dir=None, token=None, ref=None):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inline-plz]:

prospector: pylint: Redefining built-in 'dir' (redefined-builtin)
prospector: pylint: Redefining name 'url' from outer scope (line 39) (redefined-outer-name)

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):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inline-plz]: prospector: pylint: Redefining name 'url' from outer scope (line 39) (redefined-outer-name)

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