Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions providers/git/src/airflow/providers/git/bundles/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,14 @@ def __init__(

self._log.debug("bundle configured")
self.hook: GitHook | None = None
if not repo_url:
if not git_conn_id:
self._log.debug("Neither git_conn_id nor repo_url provided; loading 'git_default'")
git_conn_id = "git_default"
try:
self.hook = GitHook(git_conn_id=git_conn_id)
except AirflowException as e:
self._log.warning("Could not create GitHook", conn_id=git_conn_id, exc=e)
else:
self.repo_url = self.hook.repo_url
self._log.debug("repo_url updated from hook")
try:
self.hook = GitHook(git_conn_id=git_conn_id or "git_default")
except AirflowException as e:
self._log.warning("Could not create GitHook", conn_id=git_conn_id, exc=e)

if not repo_url and self.hook and self.hook.repo_url:
self.repo_url = self.hook.repo_url
self._log.debug("repo_url updated from hook")

def _initialize(self):
with self.lock():
Expand Down
27 changes: 27 additions & 0 deletions providers/git/tests/unit/git/bundles/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import json
import os
import re
import types
from unittest import mock
from unittest.mock import patch

Expand Down Expand Up @@ -602,3 +603,29 @@ def test_repo_url_precedence(self, conn_json, repo_url, expected):
repo_url=repo_url,
)
assert bundle.repo_url == expected

@mock.patch("airflow.providers.git.bundles.git.Repo")
def test_clone_passes_env_from_githook(self, mock_gitRepo):
def _fake_clone_from(*_, **kwargs):
if "env" not in kwargs:
raise GitCommandError("git", 128, "Permission denied")
return types.SimpleNamespace()

EXPECTED_ENV = {"GIT_SSH_COMMAND": "ssh -i /id_rsa -o StrictHostKeyChecking=no"}

mock_gitRepo.clone_from.side_effect = _fake_clone_from
mock_gitRepo.return_value = types.SimpleNamespace()

with mock.patch("airflow.providers.git.bundles.git.GitHook") as mock_githook:
mock_githook.return_value.repo_url = "git@github.com:apache/airflow.git"
mock_githook.return_value.env = EXPECTED_ENV

bundle = GitDagBundle(
name="my_repo",
git_conn_id="git_default",
repo_url="git@github.com:apache/airflow.git",
tracking_ref="main",
)
bundle._clone_bare_repo_if_required()
_, kwargs = mock_gitRepo.clone_from.call_args
assert kwargs["env"] == EXPECTED_ENV