Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _try_download_hub(planemo_hub_path):
link = _hub_link()
# Strip URL base and .tgz at the end.
basename = link.split("/")[-1].rsplit(".", 1)[0]
untar_to(link, tar_args="-Ozxvf - %s/bin/hub > '%s'" % (basename, planemo_hub_path))
communicate(["chmod", "+x", planemo_hub_path])
def clone(*args, **kwds):
"""Clone a git repository.
See :func:`command_clone` for description of arguments.
"""
command = command_clone(*args, **kwds)
return io.communicate(command)
def _communicate(self, command_builder):
stdout, _ = communicate(
command_builder.command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return stdout
def checkout(ctx, remote_repo, local_path, branch=None, remote="origin", from_branch="master"):
"""Checkout a new branch from a remote repository."""
env = git_env_for(local_path)
if not os.path.exists(local_path):
io.communicate(command_clone(ctx, remote_repo, local_path))
else:
io.communicate(["git", "fetch", remote], env=env)
if branch:
io.communicate(["git", "checkout", "%s/%s" % (remote, from_branch), "-b", branch], env=env)
else:
io.communicate(["git", "merge", "--ff-only", "%s/%s" % (remote, from_branch)], env=env)
def branch(ctx, repo_path, branch, from_branch=None):
env = git_env_for(repo_path)
cmd = ["git", "checkout", "-b", branch]
if from_branch is not None:
cmd.append(from_branch)
io.communicate(cmd, env=env)
def fork(ctx, path, **kwds):
"""Fork the target repository using ``hub``."""
hub_path = ensure_hub(ctx, **kwds)
hub_env = get_hub_env(ctx, path, **kwds)
cmd = [hub_path, "fork"]
communicate(cmd, env=hub_env)
def diff(ctx, directory, range):
"""Produce a list of diff-ed files for commit range."""
cmd_template = "cd '%s' && git diff --name-only '%s' --"
cmd = cmd_template % (directory, range)
stdout, _ = io.communicate(
cmd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True
)
return [l.strip() for l in unicodify(stdout).splitlines() if l]