Git Origins
Git Origins
Section titled “Git Origins”Git origins define where Copybara reads source code from.
git.origin
Section titled “git.origin”The basic Git origin for any Git repository:
origin = git.origin( url = "https://github.com/org/repo.git", ref = "main",)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
url | Yes | Repository URL (HTTPS or SSH) |
ref | No | Branch, tag, or commit (default: main) |
submodules | No | How to handle submodules |
include_branch_commit_logs | No | Include branch commit logs |
first_parent | No | Only follow first parent of merges |
partial_fetch | No | Enable partial clone |
Examples
Section titled “Examples”# Basic usageorigin = git.origin( url = "https://github.com/org/repo", ref = "main",)
# Specific branchorigin = git.origin( url = "https://github.com/org/repo", ref = "release/v2",)
# With submodulesorigin = git.origin( url = "https://github.com/org/repo", ref = "main", submodules = "YES", # or "NO", "RECURSIVE")
# SSH URLorigin = git.origin( url = "git@github.com:org/repo.git", ref = "main",)
# Only first parent (cleaner history)origin = git.origin( url = "https://github.com/org/repo", ref = "main", first_parent = True,)git.github_origin
Section titled “git.github_origin”GitHub-specific origin with extra features:
origin = git.github_origin( url = "https://github.com/org/repo", ref = "main",)Additional Parameters
Section titled “Additional Parameters”| Parameter | Description |
|---|---|
review_state | Only process commits with this review state |
review_approvers | Users whose approval counts |
api_checker | Custom API checker |
# Only sync approved commitsorigin = git.github_origin( url = "https://github.com/org/repo", ref = "main", review_state = "APPROVED", review_approvers = ["maintainer1", "maintainer2"],)git.github_pr_origin
Section titled “git.github_pr_origin”Read from GitHub pull requests:
origin = git.github_pr_origin( url = "https://github.com/org/repo", branch = "main",)Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
url | Repository URL |
branch | Base branch for PRs |
state | PR state filter (OPEN, CLOSED, ALL) |
labels | Only PRs with these labels |
required_labels | Labels that must be present |
required_status_context_names | CI checks that must pass |
Examples
Section titled “Examples”# All open PRsorigin = git.github_pr_origin( url = "https://github.com/org/repo", branch = "main", state = "OPEN",)
# Only PRs with specific labelorigin = git.github_pr_origin( url = "https://github.com/org/repo", branch = "main", required_labels = ["ready-to-import"],)
# PRs with passing CIorigin = git.github_pr_origin( url = "https://github.com/org/repo", branch = "main", required_status_context_names = ["ci/build", "ci/test"],)git.gerrit_origin
Section titled “git.gerrit_origin”Read from Gerrit repositories:
origin = git.gerrit_origin( url = "https://gerrit.example.com/repo", ref = "refs/heads/main",)Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
url | Gerrit repository URL |
ref | Reference to sync |
change_number_url | URL pattern for changes |
Submodule Handling
Section titled “Submodule Handling”Control how submodules are processed:
origin = git.origin( url = "https://github.com/org/repo", ref = "main", submodules = "RECURSIVE", # Recursively init submodules)Options:
"NO"- Ignore submodules (default)"YES"- Initialize submodules (one level)"RECURSIVE"- Recursively initialize all submodules
Version Selection
Section titled “Version Selection”The ref parameter accepts:
| Type | Example | Description |
|---|---|---|
| Branch | main | Head of branch |
| Tag | v1.0.0 | Specific tag |
| Commit | abc123 | Specific commit |
| Full ref | refs/heads/main | Full Git reference |
# Branchorigin = git.origin(url = ..., ref = "main")
# Tagorigin = git.origin(url = ..., ref = "v1.0.0")
# Commitorigin = git.origin(url = ..., ref = "abc123def456")