mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 23:10:42 +01:00
scm: implement pygit2 resolve rev and native checkout (#5270)
* pygit2: implement get/set/remove refs * pygit: implement iter_refs * pygit: implement resolve_rev * pygit2: implement working tree checkout * pygit2: implement reset, explicitly read/write index when used * pygit2: checkout does not need to reset index * pygit2: handle "-" branch shorthand in checkout * tests: install post-checkout hook should be run via gitpython * exp apply: use stricter exception handling for merge conflict * pygit: fix index read/write usage * gitpython: handle untracked file conflicts in stash apply * fix flaky/race index issue
This commit is contained in:
@@ -370,14 +370,15 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
except GitCommandError as exc:
|
||||
raise SCMError(f"Failed to set ref '{name}'") from exc
|
||||
|
||||
def get_ref(
|
||||
self, name: str, follow: Optional[bool] = True
|
||||
) -> Optional[str]:
|
||||
def get_ref(self, name: str, follow: bool = True) -> Optional[str]:
|
||||
from git.exc import GitCommandError
|
||||
|
||||
if name == "HEAD":
|
||||
try:
|
||||
return self.repo.head.commit.hexsha
|
||||
if follow or self.repo.head.is_detached:
|
||||
return self.repo.head.commit.hexsha
|
||||
else:
|
||||
return f"refs/heads/{self.repo.active_branch}"
|
||||
except (GitCommandError, ValueError):
|
||||
return None
|
||||
elif name.startswith("refs/heads/"):
|
||||
@@ -495,7 +496,8 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method
|
||||
try:
|
||||
self.git.stash("apply", rev)
|
||||
except GitCommandError as exc:
|
||||
if "CONFLICT" in str(exc):
|
||||
out = str(exc)
|
||||
if "CONFLICT" in out or "already exists" in out:
|
||||
raise MergeConflictError(
|
||||
"Stash apply resulted in merge conflicts"
|
||||
) from exc
|
||||
|
||||
Reference in New Issue
Block a user