Skip to main content
Version: 1.33.0 (latest)

dlt.common.libs.git

check_ref_name​

def check_ref_name(ref: Optional[str]) -> None

View source on GitHub

Refuses a ref that git reads as an option.

Raises:

  • ValueError - ref starts with -, or contains whitespace or control characters.

is_clean_and_synced​

def is_clean_and_synced(repo: Repo) -> bool

View source on GitHub

Checks if repo is clean and synced with origin

get_default_branch​

def get_default_branch(repo: Repo) -> str

View source on GitHub

The default branch of origin.

Raises:

  • GitError - origin/HEAD is missing or does not point to a branch.

ensure_remote_head​

def ensure_remote_head(repo_path: str,
branch: Optional[str] = None,
with_git_command: Optional[str] = None,
path: Optional[str] = None,
origin_url: Optional[str] = None) -> None

View source on GitHub

Updates repository from origin and ensures it's clean and synced.

Uses sparse checkout when path is specified, fetching only the specified directory instead of the entire repository tree.

Arguments:

  • repo_path - Local path to the git repository.
  • branch - Branch to checkout. Defaults to repository's default branch.
  • with_git_command - Custom GIT_SSH_COMMAND for authentication.
  • path - Directory path for sparse checkout. When set, only this path is checked out, reducing download size and time.
  • origin_url - Expected URL of origin. When set, a clone of another URL fails.

Raises:

  • RepositoryDirtyError - If repository has uncommitted changes or is not synced with origin.
  • GitError - If the repository has no origin, if origin is not origin_url, or if the repository is sparse without path or full with path.

force_clone_repo​

def force_clone_repo(repo_url: str,
repo_storage: FileStorage,
repo_name: str,
branch: Optional[str] = None,
with_git_command: Optional[str] = None,
path: Optional[str] = None) -> None

View source on GitHub

Deletes existing repository and performs fresh clone.

Removes repo_storage.root/repo_name if it exists, then clones from repo_url. Uses sparse checkout when path is specified to download only the specified directory, reducing clone time and disk usage.

Arguments:

  • repo_url - Git repository URL to clone from.
  • repo_storage - FileStorage instance managing the clone destination.
  • repo_name - Directory name for the cloned repository.
  • branch - Branch to checkout after cloning.
  • with_git_command - Custom GIT_SSH_COMMAND for authentication.
  • path - Directory path for sparse checkout. When set, only this path is cloned using --filter=blob:none.

get_fresh_repo_files​

def get_fresh_repo_files(repo_location: str,
working_dir: str = None,
branch: Optional[str] = None,
with_git_command: Optional[str] = None,
path: Optional[str] = None) -> FileStorage

View source on GitHub

Returns FileStorage with up-to-date repository files.

If repo_location is a local directory, returns storage pointing to it. If it's a git URL, clones or updates the repository in working_dir/repo_name. Supports sparse checkout to fetch only a specific directory path.

Arguments:

  • repo_location - Local directory path or git repository URL.
  • working_dir - Directory where repository will be cloned if repo_location is URL.
  • branch - Branch to checkout.
  • with_git_command - Custom GIT_SSH_COMMAND for authentication.
  • path - Directory path for sparse checkout. Downloads only this directory, improving performance for large repositories.

Returns:

FileStorage instance pointing to repository files (or specified path within).

is_head_detached​

def is_head_detached(repo_location: str, working_dir: str) -> bool

View source on GitHub

Tells if the clone of repo_location in working_dir has a tag or a commit checked out instead of a branch. A local folder or a missing clone is not detached.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.