Skip to content

Commit e7ccf98

Browse files
committed
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.
1 parent 345931d commit e7ccf98

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

java/com/google/copybara/git/GitRepository.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -1004,21 +1004,30 @@ public void abortCherryPick() throws RepoException {
10041004
public class AddCmd {
10051005

10061006
private final boolean force;
1007+
private final boolean renormalize;
10071008
private final boolean all;
10081009
private final Iterable<String> files;
10091010
@Nullable private final String pathSpecFromFile;
10101011

1011-
private AddCmd(boolean force, boolean all, Iterable<String> files, String pathSpecFromFile) {
1012+
1013+
private AddCmd(boolean force, boolean all, Iterable<String> files, String pathSpecFromFile, boolean renormalize) {
10121014
this.force = force;
10131015
this.all = all;
1016+
this.renormalize = renormalize;
10141017
this.files = checkNotNull(files);
10151018
this.pathSpecFromFile = pathSpecFromFile;
10161019
}
10171020

10181021
/** Force the add */
10191022
@CheckReturnValue
10201023
public AddCmd force() {
1021-
return new AddCmd(/*force=*/ true, all, files, pathSpecFromFile);
1024+
return new AddCmd(/*force=*/ true, all, files, pathSpecFromFile, renormalize);
1025+
}
1026+
1027+
/** Renormalize the add */
1028+
@CheckReturnValue
1029+
public AddCmd renormalize() {
1030+
return new AddCmd(/*force=*/ true, all, files, pathSpecFromFile, true);
10221031
}
10231032

10241033
/** Add all the unstagged files to the index */
@@ -1027,7 +1036,7 @@ public AddCmd all() {
10271036
Preconditions.checkState(Iterables.isEmpty(files), "'all' and passing files is incompatible");
10281037
Preconditions.checkState(
10291038
pathSpecFromFile == null, "'all' and pathSpecFromFile is incompatible");
1030-
return new AddCmd(force, /*all=*/ true, files, pathSpecFromFile);
1039+
return new AddCmd(force, /*all=*/ true, files, pathSpecFromFile, renormalize);
10311040
}
10321041

10331042
/** Configure the files to add to the index */
@@ -1036,7 +1045,7 @@ public AddCmd files(Iterable<String> files) {
10361045
Preconditions.checkState(!all, "'all' and passing files is incompatible");
10371046
Preconditions.checkState(
10381047
pathSpecFromFile == null, "'pathSpecFromFile' and passing files is incompatible");
1039-
return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile);
1048+
return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile, renormalize);
10401049
}
10411050

10421051
/** Configure the files to add to the index */
@@ -1045,7 +1054,7 @@ public AddCmd pathSpecFromFile(String pathSpecFromFile) {
10451054
Preconditions.checkState(!all, "'pathSpecFromFile' and passing files is incompatible");
10461055
Preconditions.checkState(
10471056
Iterables.isEmpty(files), "'pathSpecFromFile' and passing files is incompatible");
1048-
return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile);
1057+
return new AddCmd(force, /*all=*/ false, files, pathSpecFromFile, renormalize);
10491058
}
10501059

10511060
/** Configure the files to add to the index */
@@ -1063,7 +1072,9 @@ public void run() throws RepoException {
10631072
if (all) {
10641073
params.add("--all");
10651074
}
1066-
1075+
if (renormalize) {
1076+
params.add("--renormalize");
1077+
}
10671078
if (pathSpecFromFile != null) {
10681079
params.add("--pathspec-from-file=" + pathSpecFromFile);
10691080
}
@@ -1078,7 +1089,7 @@ public void run() throws RepoException {
10781089
*/
10791090
@CheckReturnValue
10801091
public AddCmd add() {
1081-
return new AddCmd(/*force*/ false, /*all*/ false, /*files*/ ImmutableSet.of(), null);
1092+
return new AddCmd(/*force*/ false, /*all*/ false, /*files*/ ImmutableSet.of(), null, false);
10821093
}
10831094

10841095
/**

0 commit comments

Comments
 (0)