Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3672,7 +3672,7 @@ Implicit labels that can be used/exposed:
- GITHUB_PR_REVIEWER_OTHER: A repeated label with the login of users that have participated in the review but cannot approve the import. Only populated if `review_state` field is set.


<code><a href="#origin">origin</a></code> <code>git.github_pr_origin(<a href=#git.github_pr_origin.url>url</a>, <a href=#git.github_pr_origin.use_merge>use_merge</a>=False, <a href=#git.github_pr_origin.required_labels>required_labels</a>=[], <a href=#git.github_pr_origin.required_status_context_names>required_status_context_names</a>=[], <a href=#git.github_pr_origin.required_check_runs>required_check_runs</a>=[], <a href=#git.github_pr_origin.retryable_labels>retryable_labels</a>=[], <a href=#git.github_pr_origin.submodules>submodules</a>='NO', <a href=#git.github_pr_origin.excluded_submodules>excluded_submodules</a>=[], <a href=#git.github_pr_origin.baseline_from_branch>baseline_from_branch</a>=False, <a href=#git.github_pr_origin.first_parent>first_parent</a>=True, <a href=#git.github_pr_origin.partial_fetch>partial_fetch</a>=False, <a href=#git.github_pr_origin.state>state</a>='OPEN', <a href=#git.github_pr_origin.review_state>review_state</a>=None, <a href=#git.github_pr_origin.review_approvers>review_approvers</a>=["COLLABORATOR", "MEMBER", "OWNER"], <a href=#git.github_pr_origin.api_checker>api_checker</a>=None, <a href=#git.github_pr_origin.patch>patch</a>=None, <a href=#git.github_pr_origin.branch>branch</a>=None, <a href=#git.github_pr_origin.describe_version>describe_version</a>=None, <a href=#git.github_pr_origin.credentials>credentials</a>=None, <a href=#git.github_pr_origin.github_host_name>github_host_name</a>='github.com')</code>
<code><a href="#origin">origin</a></code> <code>git.github_pr_origin(<a href=#git.github_pr_origin.url>url</a>, <a href=#git.github_pr_origin.use_merge>use_merge</a>=False, <a href=#git.github_pr_origin.required_labels>required_labels</a>=[], <a href=#git.github_pr_origin.required_status_context_names>required_status_context_names</a>=[], <a href=#git.github_pr_origin.required_check_runs>required_check_runs</a>=[], <a href=#git.github_pr_origin.retryable_labels>retryable_labels</a>=[], <a href=#git.github_pr_origin.submodules>submodules</a>='NO', <a href=#git.github_pr_origin.excluded_submodules>excluded_submodules</a>=[], <a href=#git.github_pr_origin.baseline_from_branch>baseline_from_branch</a>=False, <a href=#git.github_pr_origin.first_parent>first_parent</a>=True, <a href=#git.github_pr_origin.partial_fetch>partial_fetch</a>=False, <a href=#git.github_pr_origin.state>state</a>='OPEN', <a href=#git.github_pr_origin.review_state>review_state</a>=None, <a href=#git.github_pr_origin.review_approvers>review_approvers</a>=["COLLABORATOR", "MEMBER", "OWNER"], <a href=#git.github_pr_origin.api_checker>api_checker</a>=None, <a href=#git.github_pr_origin.patch>patch</a>=None, <a href=#git.github_pr_origin.branch>branch</a>=None, <a href=#git.github_pr_origin.describe_version>describe_version</a>=None, <a href=#git.github_pr_origin.enable_lfs>enable_lfs</a>=False, <a href=#git.github_pr_origin.credentials>credentials</a>=None, <a href=#git.github_pr_origin.github_host_name>github_host_name</a>='github.com')</code>


<h4 id="parameters.git.github_pr_origin">Parameters:</h4>
Expand All @@ -3697,6 +3697,7 @@ Parameter | Description
<span id=git.github_pr_origin.patch href=#git.github_pr_origin.patch>patch</span> | <code><a href="#transformation">transformation</a></code> or <code>NoneType</code><br><p>Patch the checkout dir. The difference with `patch.apply` transformation is that here we can apply it using three-way</p>
<span id=git.github_pr_origin.branch href=#git.github_pr_origin.branch>branch</span> | <code><a href="#string">string</a></code> or <code>NoneType</code><br><p>If set, it will only migrate pull requests for this base branch</p>
<span id=git.github_pr_origin.describe_version href=#git.github_pr_origin.describe_version>describe_version</span> | <code><a href="#bool">bool</a></code> or <code>NoneType</code><br><p>Download tags and use 'git describe' to create four labels with a meaningful version identifier:<br><br> - `GIT_DESCRIBE_CHANGE_VERSION`: The version for the change or changes being migrated. The value changes per change in `ITERATIVE` mode and will be the latest migrated change in `SQUASH` (In other words, doesn't include excluded changes). this is normally what users want to use.<br> - `GIT_DESCRIBE_REQUESTED_VERSION`: `git describe` for the requested/head version. Constant in `ITERATIVE` mode and includes filtered changes.<br> -`GIT_DESCRIBE_FIRST_PARENT`: `git describe` for the first parent version.<br> -`GIT_SEQUENTIAL_REVISION_NUMBER`: The sequential number of the commit. Falls back to the SHA1 if not applicable.<br></p>
<span id=git.github_pr_origin.enable_lfs href=#git.github_pr_origin.enable_lfs>enable_lfs</span> | <code><a href="#bool">bool</a></code><br><p>If true, Large File Storage support is enabled for the origin.</p>
<span id=git.github_pr_origin.credentials href=#git.github_pr_origin.credentials>credentials</span> | <code>UsernamePasswordIssuer</code> or <code>NoneType</code><br><p>EXPERIMENTAL: Read credentials from config file to access the Git Repo. This expects a 'credentials.username_password' specifying the username to use for the remote git host and a password or token. This is gated by the '--use-credentials-from-config' flag</p>
<span id=git.github_pr_origin.github_host_name href=#git.github_pr_origin.github_host_name>github_host_name</span> | <code><a href="#string">string</a></code><br><p>**EXPERIMENTAL feature.** The host name of the GitHub repository, used to construct the URL. Required for GitHub Enterprise.</p>

Expand Down
9 changes: 9 additions & 0 deletions java/com/google/copybara/git/GitHubPrOrigin.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public class GitHubPrOrigin implements Origin<GitRevision> {
private final GitHubHost ghHost;
private final GitHubPrOriginOptions gitHubPrOriginOptions;
private final ApprovalsProvider provider;
private final boolean enableLfs;
@Nullable private final CredentialFileHandler credentials;
@Nullable private final GitRepositoryHook gitRepositoryHook;

Expand Down Expand Up @@ -176,6 +177,7 @@ public class GitHubPrOrigin implements Origin<GitRevision> {
boolean describeVersion,
GitHubHost ghHost,
ApprovalsProvider provider,
boolean enableLfs,
@Nullable CredentialFileHandler credentials,
@Nullable GitRepositoryHook gitRepositoryHook) {
this.url = checkNotNull(url);
Expand Down Expand Up @@ -204,6 +206,7 @@ public class GitHubPrOrigin implements Origin<GitRevision> {
this.describeVersion = describeVersion;
this.ghHost = ghHost;
this.provider = checkNotNull(provider);
this.enableLfs = enableLfs;
this.credentials = credentials;
this.gitRepositoryHook = gitRepositoryHook;
}
Expand Down Expand Up @@ -711,6 +714,9 @@ private void checkReviewApprovers(
@VisibleForTesting
public GitRepository getRepository() throws RepoException {
GitRepository repo = gitOptions.cachedBareRepoForUrl(url);
if (enableLfs) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this? (Seems required to figure out where to fetch from.)

repo.setRemoteOriginUrl(url);
}
if (credentials != null) {
try {
credentials.install(repo, gitOptions.getConfigCredsFile(generalOptions));
Expand Down Expand Up @@ -894,6 +900,9 @@ public ImmutableSetMultimap<String, String> describe(Glob originFiles) {
if (!getRetryableLabels().isEmpty()) {
builder.putAll(GitHubUtil.RETRYABLE_LABELS, getRetryableLabels());
}
if (enableLfs) {
builder.put("enableLfs", Boolean.toString(enableLfs));
}
return builder.build();
}

Expand Down
10 changes: 9 additions & 1 deletion java/com/google/copybara/git/GitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,12 @@ public GitOrigin gerritOrigin(
named = true,
positional = false,
doc = DESCRIBE_VERSION_FIELD_DOC),
@Param(
name = "enable_lfs",
defaultValue = "False",
named = true,
positional = false,
doc = "If true, Large File Storage support is enabled for the origin."),
@Param(
name = "credentials",
allowedTypes = {
Expand Down Expand Up @@ -1237,6 +1243,7 @@ public Origin<GitRevision> githubPrOrigin(
Object patch,
Object branch,
Object describeVersion,
Boolean enableLfs,
@Nullable Object credentials,
String gitHubHostName,
StarlarkThread thread)
Expand Down Expand Up @@ -1299,7 +1306,7 @@ public Origin<GitRevision> githubPrOrigin(
workflowName,
false,
githubPostSubmitApprovalsProvider(fixedUrl, ref, credHandler),
/* enableLfs= */ false,
enableLfs,
credHandler,
null);
}
Expand Down Expand Up @@ -1336,6 +1343,7 @@ public Origin<GitRevision> githubPrOrigin(
convertDescribeVersion(describeVersion),
gitHubHost,
githubPreSubmitApprovalsProvider(fixedUrl, credHandler),
enableLfs,
credHandler,
/* gitRepositoryHook= */ null);
}
Expand Down
23 changes: 23 additions & 0 deletions javatests/com/google/copybara/git/GitHubPrOriginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -1276,6 +1277,28 @@ public void testDescribeBranch() throws Exception {
.contains("dev");
}

@Test
public void testEnableLfs() throws Exception {
GitHubPrOrigin origin =
githubPrOrigin(
"url = 'https://github.com/google/example'",
"enable_lfs = True");
ImmutableSetMultimap<String, String> actual = origin.describe(Glob.ALL_FILES);
assertThat(actual.get("enableLfs")).containsExactly("true");

GitRepository repo = origin.getRepository();
assertThat(repo.simpleCommand("config", "remote.origin.url").getStdout().trim())
.isEqualTo("https://github.com/google/example");
}

@Test
public void testEnableLfs_defaultFalse() throws Exception {
GitHubPrOrigin origin =
githubPrOrigin("url = 'https://github.com/google/example'");
ImmutableSetMultimap<String, String> actual = origin.describe(Glob.ALL_FILES);
assertThat(actual.containsKey("enableLfs")).isFalse();
}

private GitRevision checkReviewApprovers(String... configLines)
throws RepoException, IOException, ValidationException {
GitRepository remote = gitUtil.mockRemoteRepo("github.com/google/example");
Expand Down