kopia lustrzana https://github.com/jupyterhub/repo2docker
adding a ref checker util
rodzic
8beb5e07bc
commit
728fb9707e
|
@ -34,7 +34,7 @@ from .buildpacks import (
|
||||||
)
|
)
|
||||||
from .utils import (
|
from .utils import (
|
||||||
execute_cmd, ByteSpecification, maybe_cleanup, is_valid_docker_image_name,
|
execute_cmd, ByteSpecification, maybe_cleanup, is_valid_docker_image_name,
|
||||||
validate_and_generate_port_mapping
|
validate_and_generate_port_mapping, check_ref
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,11 +175,7 @@ class Repo2Docker(Application):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if ref:
|
if ref:
|
||||||
if self.repo_type == "remote" and not ref.startswith('origin/'):
|
ref = check_ref(ref)
|
||||||
# Ensure that the ref has `origin` in front
|
|
||||||
self.log.info("Ref did not have a remote specified, "
|
|
||||||
"adding 'origin/' to ref.")
|
|
||||||
ref = '/'.join(["origin", ref])
|
|
||||||
try:
|
try:
|
||||||
for line in execute_cmd(['git', 'reset', '--hard', ref],
|
for line in execute_cmd(['git', 'reset', '--hard', ref],
|
||||||
cwd=checkout_path,
|
cwd=checkout_path,
|
||||||
|
|
|
@ -270,3 +270,28 @@ class ByteSpecification(Integer):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return int(float(num) * self.UNIT_SUFFIXES[suffix])
|
return int(float(num) * self.UNIT_SUFFIXES[suffix])
|
||||||
|
|
||||||
|
|
||||||
|
def check_ref(ref):
|
||||||
|
"""Prepare a ref and ensure it works with git reset --hard."""
|
||||||
|
ref_checks = {'tag': "refs/tags/{}",
|
||||||
|
'branch': "refs/heads/{}",
|
||||||
|
'remote': "refs/remotes/origin/{}",
|
||||||
|
'commit': "{}^{{commit}}"}
|
||||||
|
chosen_kind = None
|
||||||
|
for kind, check in ref_checks:
|
||||||
|
check = check.split('/')[-1]
|
||||||
|
parts = ["git", "show-ref", "--verify", check.format(ref)]
|
||||||
|
success = subprocess.call(parts)
|
||||||
|
if success:
|
||||||
|
break
|
||||||
|
|
||||||
|
if chosen_kind is None:
|
||||||
|
raise ValueError("Could not resolve the ref properly, ensure that "
|
||||||
|
"it is a commit hash / tag / branch name.")
|
||||||
|
if chosen_kind == "remote" and not check.startswith('origin/'):
|
||||||
|
# Ensure that the ref has `origin` in front
|
||||||
|
self.log.info("Ref did not have a remote specified, "
|
||||||
|
"adding 'origin/' to ref.\n")
|
||||||
|
check = '/'.join(["origin", check])
|
||||||
|
return check
|
||||||
|
|
Ładowanie…
Reference in New Issue