ephraimbuddy commented on code in PR #72923:
URL: https://github.com/apache/airflow/pull/72923#discussion_r4739531984
##########
providers/git/src/airflow/providers/git/bundles/git.py:
##########
@@ -314,6 +304,50 @@ def _clone_repo_if_required(self) -> None:
def _uses_github_app_auth(self) -> bool:
return self.hook is not None and self.hook.uses_github_app_auth
+ @property
+ def _staging_repo_path(self) -> Path:
+ """Where a working clone is assembled before it is moved onto
``repo_path``."""
+ return self.base_dir / f".staging-{self.repo_path.name}"
+
+ def _clone_working_repo(self) -> None:
+ """
+ Assemble the working clone in a staging directory and move it onto
``repo_path``.
+
+ ``Repo.clone_from`` writes into its target as it goes, so a process
killed part way
+ through a clone leaves behind a directory that git can open but that
cannot check out
+ the tracking ref, and nothing removes it. Cloning into a sibling
directory and renaming
+ it means an interrupted clone never leaves a half-written
``repo_path``, so the next
+ initialization clones again rather than reusing a repository that can
never recover.
+ """
+ staging_path = self._staging_repo_path
+ # Left behind by an attempt that did not survive long enough to clean
up after itself.
+ if os.path.exists(staging_path):
+ self._log.info("Discarding staging directory from an earlier
clone", path=staging_path)
+ shutil.rmtree(staging_path)
+ try:
+ Repo.clone_from(
+ url=self.bare_repo_path,
+ to_path=staging_path,
+ multi_options=["--sparse", "--no-checkout"] if
self.sparse_dirs else None,
Review Comment:
For a non-sparse bundle this renames a clone that is on the remote's default
branch, and `_initialize` then runs `checkout(self.tracking_ref)` in place on
`repo_path`. When `tracking_ref` is another branch, a tag or a SHA, a SIGTERM
during that checkout leaves the same state as #72922.
Can we always clone with `--no-checkout` and check out `tracking_ref` here
before the rename, as the sparse branch already does? The checkout in
`_initialize` then does nothing on a fresh clone.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]