Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass --renormalize during git add to fix LFS usage in destination repo #301

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion java/com/google/copybara/git/GitDestination.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,11 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,

console.progress("Git Destination: Adding all files");
try (ProfilerTask ignored = generalOptions.profiler().start("add_files")) {
alternate.add().force().all().run();
if(generalOptions.isForced()){
alternate.add().force().all().run();
}else{
alternate.add().force().renormalize().all().run();
}
Copy link
Author

Choose a reason for hiding this comment

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

We discovered that, on initial sync of a branch w/ --force flag usage in global options, adding --renormalize results in a situation where no new files are added to that initial destination commit. Hence the conditional. Perhaps this isn't the best design; if so, we request reviewer's input on what can be a better design.

}

console.progress("Git Destination: Excluding files");
Expand Down
25 changes: 18 additions & 7 deletions java/com/google/copybara/git/GitRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1004,21 +1004,30 @@ public void abortCherryPick() throws RepoException {
public class AddCmd {

private final boolean force;
private final boolean renormalize;
private final boolean all;
private final Iterable<String> files;
@Nullable private final String pathSpecFromFile;

private AddCmd(boolean force, boolean all, Iterable<String> files, String pathSpecFromFile) {

private AddCmd(boolean force, boolean all, Iterable<String> files, String pathSpecFromFile, boolean renormalize) {
this.force = force;
this.all = all;
this.renormalize = renormalize;
this.files = checkNotNull(files);
this.pathSpecFromFile = pathSpecFromFile;
}

/** 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 */
Expand All @@ -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 */
Expand All @@ -1036,7 +1045,7 @@ public AddCmd files(Iterable<String> 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 */
Expand All @@ -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 */
Expand All @@ -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);
}
Expand All @@ -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);
}

/**
Expand Down