Skip to content

Commit

Permalink
Rename head to tracking ref (apache#44585)
Browse files Browse the repository at this point in the history
Head is confusing cus in git speak it means "what you have checked out".  That's not what we mean here.  Here we're trying to describe, most commonly, the branch in the repo that the user wants this bundle to track or "follow".  Branch would be a good name, but technically it could also be a tag, or even a commit hash.
  • Loading branch information
dstandish authored Dec 3, 2024
1 parent 8ca061d commit 4ffa6af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions airflow/dag_processing/bundles/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ class GitDagBundle(BaseDagBundle):
and then do a clone for each version from there.
:param repo_url: URL of the git repository
:param head: Branch or tag for this DAG bundle
:param tracking_ref: Branch or tag for this DAG bundle
:param subdir: Subdirectory within the repository where the DAGs are stored (Optional)
"""

supports_versioning = True

def __init__(self, *, repo_url: str, head: str, subdir: str | None = None, **kwargs) -> None:
def __init__(self, *, repo_url: str, tracking_ref: str, subdir: str | None = None, **kwargs) -> None:
super().__init__(**kwargs)
self.repo_url = repo_url
self.head = head
self.tracking_ref = tracking_ref
self.subdir = subdir

self.bare_repo_path = self._dag_bundle_root_storage_path / "git" / self.name
self.repo_path = (
self._dag_bundle_root_storage_path / "git" / (self.name + f"+{self.version or self.head}")
self._dag_bundle_root_storage_path / "git" / (self.name + f"+{self.version or self.tracking_ref}")
)
self._clone_bare_repo_if_required()
self._ensure_version_in_bare_repo()
self._clone_repo_if_required()
self.repo.git.checkout(self.head)
self.repo.git.checkout(self.tracking_ref)

if self.version:
if not self._has_version(self.repo, self.version):
Expand Down
20 changes: 11 additions & 9 deletions tests/dag_processing/test_dag_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def test_supports_versioning(self):

def test_uses_dag_bundle_root_storage_path(self, git_repo):
repo_path, repo = git_repo
bundle = GitDagBundle(name="test", repo_url=repo_path, head="master")
bundle = GitDagBundle(name="test", repo_url=repo_path, tracking_ref="master")
assert str(bundle._dag_bundle_root_storage_path) in str(bundle.path)

def test_get_current_version(self, git_repo):
repo_path, repo = git_repo
bundle = GitDagBundle(name="test", repo_url=repo_path, head="master")
bundle = GitDagBundle(name="test", repo_url=repo_path, tracking_ref="master")

assert bundle.get_current_version() == repo.head.commit.hexsha

Expand All @@ -110,7 +110,9 @@ def test_get_specific_version(self, git_repo):
repo.index.add([file_path])
repo.index.commit("Another commit")

bundle = GitDagBundle(name="test", version=starting_commit.hexsha, repo_url=repo_path, head="master")
bundle = GitDagBundle(
name="test", version=starting_commit.hexsha, repo_url=repo_path, tracking_ref="master"
)

assert bundle.get_current_version() == starting_commit.hexsha

Expand All @@ -132,7 +134,7 @@ def test_get_tag_version(self, git_repo):
repo.index.add([file_path])
repo.index.commit("Another commit")

bundle = GitDagBundle(name="test", version="test", repo_url=repo_path, head="master")
bundle = GitDagBundle(name="test", version="test", repo_url=repo_path, tracking_ref="master")

assert bundle.get_current_version() == starting_commit.hexsha

Expand All @@ -149,7 +151,7 @@ def test_get_latest(self, git_repo):
repo.index.add([file_path])
repo.index.commit("Another commit")

bundle = GitDagBundle(name="test", repo_url=repo_path, head="master")
bundle = GitDagBundle(name="test", repo_url=repo_path, tracking_ref="master")

assert bundle.get_current_version() != starting_commit.hexsha

Expand All @@ -160,7 +162,7 @@ def test_refresh(self, git_repo):
repo_path, repo = git_repo
starting_commit = repo.head.commit

bundle = GitDagBundle(name="test", repo_url=repo_path, head="master")
bundle = GitDagBundle(name="test", repo_url=repo_path, tracking_ref="master")

assert bundle.get_current_version() == starting_commit.hexsha

Expand All @@ -184,14 +186,14 @@ def test_head(self, git_repo):
repo_path, repo = git_repo

repo.create_head("test")
bundle = GitDagBundle(name="test", repo_url=repo_path, head="test")
bundle = GitDagBundle(name="test", repo_url=repo_path, tracking_ref="test")
assert bundle.repo.head.ref.name == "test"

def test_version_not_found(self, git_repo):
repo_path, repo = git_repo

with pytest.raises(AirflowException, match="Version not_found not found in the repository"):
GitDagBundle(name="test", version="not_found", repo_url=repo_path, head="master")
GitDagBundle(name="test", version="not_found", repo_url=repo_path, tracking_ref="master")

def test_subdir(self, git_repo):
repo_path, repo = git_repo
Expand All @@ -206,7 +208,7 @@ def test_subdir(self, git_repo):
repo.index.add([file_path])
repo.index.commit("Initial commit")

bundle = GitDagBundle(name="test", repo_url=repo_path, head="master", subdir=subdir)
bundle = GitDagBundle(name="test", repo_url=repo_path, tracking_ref="master", subdir=subdir)

files_in_repo = {f.name for f in bundle.path.iterdir() if f.is_file()}
assert str(bundle.path).endswith(subdir)
Expand Down

0 comments on commit 4ffa6af

Please sign in to comment.