From a787216327f5265e6cfae409cb6c4d86b8ed8029 Mon Sep 17 00:00:00 2001 From: Gregory Kramida Date: Wed, 16 Oct 2024 13:25:15 -0400 Subject: [PATCH 1/5] fix(GitModule): add enable_lfs param to git.origin - "false" by default - value passed to call to GitOrigin.newGitOrigin, just like for github_origin - allows for LFS usage with any Git backend that supports LFS, e.g. GitLab Co-authored-by: Ashraful Islam --- java/com/google/copybara/git/GitModule.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/java/com/google/copybara/git/GitModule.java b/java/com/google/copybara/git/GitModule.java index 215548557..b7db30042 100644 --- a/java/com/google/copybara/git/GitModule.java +++ b/java/com/google/copybara/git/GitModule.java @@ -297,6 +297,12 @@ public GitModule(Options options) { + " fall back to the 'ref' param.\n" + "This is intended to help migrating to the new standard of using 'main'" + " without breaking users relying on the legacy default."), + @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 = { @@ -322,6 +328,7 @@ public GitOrigin origin( Object describeVersion, Object versionSelector, Boolean primaryBranchMigration, + Boolean enableLfs, @Nullable Object credentials, StarlarkThread thread) throws EvalException { @@ -360,7 +367,7 @@ public GitOrigin origin( ? githubPostSubmitApprovalsProvider( fixedUrl, SkylarkUtil.convertOptionalString(ref), credentialHandler) : approvalsProvider(url), - /* enableLfs= */ false, + enableLfs, credentialHandler ); } From d3b27c9c7d3d18d6d2d354cfdb1a5bf37fa9362c Mon Sep 17 00:00:00 2001 From: Gregory Kramida Date: Wed, 16 Oct 2024 13:29:10 -0400 Subject: [PATCH 2/5] fix(GitRepository): add renormalize() method - `renormalize` field is "false" by default - sets `renormalize` field to true - if `renormalize` is set to true, "--renormalize" argument is appended to the `git add` command. Co-authored-by: Ashraful Islam --- .../google/copybara/git/GitRepository.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/java/com/google/copybara/git/GitRepository.java b/java/com/google/copybara/git/GitRepository.java index ea2c6f831..14fcb765e 100644 --- a/java/com/google/copybara/git/GitRepository.java +++ b/java/com/google/copybara/git/GitRepository.java @@ -1004,13 +1004,16 @@ public void abortCherryPick() throws RepoException { public class AddCmd { private final boolean force; + private final boolean renormalize; private final boolean all; private final Iterable files; @Nullable private final String pathSpecFromFile; - private AddCmd(boolean force, boolean all, Iterable files, String pathSpecFromFile) { + + private AddCmd(boolean force, boolean all, Iterable files, String pathSpecFromFile, boolean renormalize) { this.force = force; this.all = all; + this.renormalize = renormalize; this.files = checkNotNull(files); this.pathSpecFromFile = pathSpecFromFile; } @@ -1018,7 +1021,13 @@ private AddCmd(boolean force, boolean all, Iterable files, String pathSp /** Force the add */ @CheckReturnValue public AddCmd force() { - return new AddCmd(/*force=*/ true, all, files, pathSpecFromFile); + return new AddCmd(/*force=*/ true, all, files, pathSpecFromFile, renormalize); + } + + /** Renormalize the add */ + @CheckReturnValue + public AddCmd renormalize() { + return new AddCmd(/*force=*/ true, all, files, pathSpecFromFile, true); } /** Add all the unstagged files to the index */ @@ -1027,7 +1036,7 @@ public AddCmd all() { Preconditions.checkState(Iterables.isEmpty(files), "'all' and passing files is incompatible"); Preconditions.checkState( pathSpecFromFile == null, "'all' and pathSpecFromFile is incompatible"); - return new AddCmd(force, /*all=*/ true, files, pathSpecFromFile); + return new AddCmd(force, /*all=*/ true, files, pathSpecFromFile, renormalize); } /** Configure the files to add to the index */ @@ -1036,7 +1045,7 @@ public AddCmd files(Iterable files) { Preconditions.checkState(!all, "'all' and passing files is incompatible"); Preconditions.checkState( pathSpecFromFile == null, "'pathSpecFromFile' and passing files is incompatible"); - return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile); + return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile, renormalize); } /** Configure the files to add to the index */ @@ -1045,7 +1054,7 @@ public AddCmd pathSpecFromFile(String pathSpecFromFile) { Preconditions.checkState(!all, "'pathSpecFromFile' and passing files is incompatible"); Preconditions.checkState( Iterables.isEmpty(files), "'pathSpecFromFile' and passing files is incompatible"); - return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile); + return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile, renormalize); } /** Configure the files to add to the index */ @@ -1063,7 +1072,9 @@ public void run() throws RepoException { if (all) { params.add("--all"); } - + if (renormalize) { + params.add("--renormalize"); + } if (pathSpecFromFile != null) { params.add("--pathspec-from-file=" + pathSpecFromFile); } @@ -1078,7 +1089,7 @@ public void run() throws RepoException { */ @CheckReturnValue public AddCmd add() { - return new AddCmd(/*force*/ false, /*all*/ false, /*files*/ ImmutableSet.of(), null); + return new AddCmd(/*force*/ false, /*all*/ false, /*files*/ ImmutableSet.of(), null, false); } /** From b28f11baba08bb38556efe58b1c28aa606b6c090 Mon Sep 17 00:00:00 2001 From: Gregory Kramida Date: Wed, 16 Oct 2024 13:30:24 -0400 Subject: [PATCH 3/5] fix(GitDestination): renormalize during `git add` - enables use of Git LFS in git destinations Co-authored-by: Ashraful Islam --- java/com/google/copybara/git/GitDestination.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/com/google/copybara/git/GitDestination.java b/java/com/google/copybara/git/GitDestination.java index 37d1c19ad..1fbd42c19 100644 --- a/java/com/google/copybara/git/GitDestination.java +++ b/java/com/google/copybara/git/GitDestination.java @@ -549,7 +549,7 @@ public ImmutableList write(TransformResult transformResult, console.progress("Git Destination: Adding all files"); try (ProfilerTask ignored = generalOptions.profiler().start("add_files")) { - alternate.add().force().all().run(); + alternate.add().force().renormalize().all().run(); } console.progress("Git Destination: Excluding files"); From c81039761af9c868f3a9b4dbaf241c31c962ac56 Mon Sep 17 00:00:00 2001 From: Ashraful Islam Date: Fri, 18 Oct 2024 17:08:47 -0500 Subject: [PATCH 4/5] Revert "fix(GitModule): add enable_lfs param to git.origin" This reverts commit a787216327f5265e6cfae409cb6c4d86b8ed8029. --- java/com/google/copybara/git/GitModule.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/java/com/google/copybara/git/GitModule.java b/java/com/google/copybara/git/GitModule.java index b7db30042..215548557 100644 --- a/java/com/google/copybara/git/GitModule.java +++ b/java/com/google/copybara/git/GitModule.java @@ -297,12 +297,6 @@ public GitModule(Options options) { + " fall back to the 'ref' param.\n" + "This is intended to help migrating to the new standard of using 'main'" + " without breaking users relying on the legacy default."), - @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 = { @@ -328,7 +322,6 @@ public GitOrigin origin( Object describeVersion, Object versionSelector, Boolean primaryBranchMigration, - Boolean enableLfs, @Nullable Object credentials, StarlarkThread thread) throws EvalException { @@ -367,7 +360,7 @@ public GitOrigin origin( ? githubPostSubmitApprovalsProvider( fixedUrl, SkylarkUtil.convertOptionalString(ref), credentialHandler) : approvalsProvider(url), - enableLfs, + /* enableLfs= */ false, credentialHandler ); } From 3c2371a6f2cc775637a33cae8218df1b4e9e4498 Mon Sep 17 00:00:00 2001 From: Gregory Kramida Date: Fri, 1 Nov 2024 11:51:28 -0400 Subject: [PATCH 5/5] fix(GitDestination): don't renormalize during `git add` if --force general option is used Co-authored-by: Ashraful Islam - fix on very first (--force) revision --- java/com/google/copybara/git/GitDestination.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/java/com/google/copybara/git/GitDestination.java b/java/com/google/copybara/git/GitDestination.java index 1fbd42c19..b5fa96f89 100644 --- a/java/com/google/copybara/git/GitDestination.java +++ b/java/com/google/copybara/git/GitDestination.java @@ -549,7 +549,11 @@ public ImmutableList write(TransformResult transformResult, console.progress("Git Destination: Adding all files"); try (ProfilerTask ignored = generalOptions.profiler().start("add_files")) { - alternate.add().force().renormalize().all().run(); + if(generalOptions.isForced()){ + alternate.add().force().all().run(); + }else{ + alternate.add().force().renormalize().all().run(); + } } console.progress("Git Destination: Excluding files");