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:
Peter Rowlands (변기호)
2021-01-18 17:41:25 +02:00
committed by GitHub
parent 78e12327bc
commit 407f5607a2
7 changed files with 194 additions and 31 deletions
+7 -5
View File
@@ -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