mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 08:58:48 +00:00
cli should pull instead of delete+clone (#12607)
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
8b5e879171
commit
f39246bd7e
@ -147,9 +147,10 @@ def parse_dependencies(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _get_repo_path(gitstring: str, repo_dir: Path) -> Path:
|
def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
|
||||||
# only based on git for now
|
# only based on git for now
|
||||||
hashed = hashlib.sha256(gitstring.encode("utf-8")).hexdigest()[:8]
|
ref_str = ref if ref is not None else ""
|
||||||
|
hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode("utf-8")).hexdigest()[:8]
|
||||||
|
|
||||||
removed_protocol = gitstring.split("://")[-1]
|
removed_protocol = gitstring.split("://")[-1]
|
||||||
removed_basename = re.split(r"[/:]", removed_protocol, 1)[-1]
|
removed_basename = re.split(r"[/:]", removed_protocol, 1)[-1]
|
||||||
@ -162,12 +163,21 @@ def _get_repo_path(gitstring: str, repo_dir: Path) -> Path:
|
|||||||
|
|
||||||
def update_repo(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
|
def update_repo(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
|
||||||
# see if path already saved
|
# see if path already saved
|
||||||
repo_path = _get_repo_path(gitstring, repo_dir)
|
repo_path = _get_repo_path(gitstring, ref, repo_dir)
|
||||||
if repo_path.exists():
|
if repo_path.exists():
|
||||||
shutil.rmtree(repo_path)
|
# try pulling
|
||||||
|
try:
|
||||||
|
repo = Repo(repo_path)
|
||||||
|
if repo.active_branch.name != ref:
|
||||||
|
raise ValueError()
|
||||||
|
repo.remotes.origin.pull()
|
||||||
|
except Exception:
|
||||||
|
# if it fails, delete and clone again
|
||||||
|
shutil.rmtree(repo_path)
|
||||||
|
Repo.clone_from(gitstring, repo_path, branch=ref, depth=1)
|
||||||
|
else:
|
||||||
|
Repo.clone_from(gitstring, repo_path, branch=ref, depth=1)
|
||||||
|
|
||||||
# now we have fresh dir
|
|
||||||
Repo.clone_from(gitstring, repo_path, branch=ref, depth=1)
|
|
||||||
return repo_path
|
return repo_path
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user