Skip to content

Commit

Permalink
Set extensions.partialClone origin
Browse files Browse the repository at this point in the history
Additionally, set core.repositoryFormatVersion to 1 before config
partial fetch so that the config both works for the current git
version and the upcoming git version
Git recent changes have automatically included this config in --filter
flag.

Otherwise, we would run into this error on copybara service:
Error: Stderr: warning: unable to upgrade repository format from 0 to
 1: fatal: unable to upgrade repository format to enable worktreeConfig

"into master" will append to merge msg "Merge branch 'feature'" in the
upcoming changes. Thus,use contains instead of verified the message.

PiperOrigin-RevId: 320660022
Change-Id: I8ae3a21384746ba4172eb2bce4060aaf6928f236
  • Loading branch information
qfc authored and Copybara-Service committed Jul 13, 2020
1 parent 069c00d commit ca76c0b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
3 changes: 2 additions & 1 deletion java/com/google/copybara/git/GitRepository.java
Expand Up @@ -1042,7 +1042,8 @@ public GitRepository withCredentialHelper(String credentialHelper)

public GitRepository withPartialClone() {
try {
this.simpleCommand("config", "extensions.partialClone", "true");
this.simpleCommand("config", "core.repositoryFormatVersion", "1");
this.simpleCommand("config", "extensions.partialClone", "origin");
} catch (Exception e) {
logger.atInfo().withCause(e).log("Partial Clone %s", e);
}
Expand Down
52 changes: 31 additions & 21 deletions javatests/com/google/copybara/git/GitOriginTest.java
Expand Up @@ -713,7 +713,7 @@ public void testFirstParent() throws Exception {

// We don't visit 'feature' branch since the visit is using --first-parent
assertThat(visited).hasSize(4);
assertThat(visited.get(0).firstLineMessage()).isEqualTo("Merge branch 'feature'");
assertThat(visited.get(0).firstLineMessage()).contains("Merge branch 'feature'");
assertThat(visited.get(1).firstLineMessage()).isEqualTo("master2");
assertThat(visited.get(2).firstLineMessage()).isEqualTo("master1");
assertThat(visited.get(3).firstLineMessage()).isEqualTo("first file");
Expand All @@ -737,11 +737,17 @@ public void testFirstParent() throws Exception {
// Now because we don't use --first-parent we visit feature branch.
assertThat(visited).hasSize(6);
// First commit is the merge
assertThat(visited.get(0).firstLineMessage()).isEqualTo("Merge branch 'feature'");
assertThat(visited.get(0).firstLineMessage()).contains("Merge branch 'feature'");
// The rest can come in a different order depending on the time difference, as git log
// ordering is undefined for same time.
assertThat(Lists.transform(visited, Change::firstLineMessage)).containsExactly(
"Merge branch 'feature'", "master2", "change3", "master1", "change2", "first file");
List<String> visitedMsgList = Lists.transform(visited, Change::firstLineMessage);
assertThat(visitedMsgList).hasSize(6);
assertThat(visitedMsgList.get(0)).contains("Merge branch 'feature'");
assertThat(visitedMsgList.get(1)).contains("master2");
assertThat(visitedMsgList.get(2)).contains("change3");
assertThat(visitedMsgList.get(3)).contains("master1");
assertThat(visitedMsgList.get(4)).contains("change2");
assertThat(visitedMsgList.get(5)).contains("first file");

changes = reader.changes(/*fromRef=*/null, lastCommitRef).getChanges();
assertThat(Lists.transform(changes.reverse(), Change::getRevision)).isEqualTo(
Expand Down Expand Up @@ -796,7 +802,7 @@ public void testChangesMerge() throws Exception {
assertThat(changes).hasSize(3);
assertThat(changes.get(0).getMessage()).isEqualTo("master1\n");
assertThat(changes.get(1).getMessage()).isEqualTo("master2\n");
assertThat(changes.get(2).getMessage()).isEqualTo("Merge branch 'feature'\n");
assertThat(changes.get(2).getMessage()).contains("Merge branch 'feature'");
for (Change<GitRevision> change : changes) {
assertThat(change.getAuthor().getEmail()).isEqualTo("john@name.com");
assertThat(change.getDateTime()).isAtLeast(beforeTime);
Expand All @@ -823,32 +829,36 @@ public void testIncludeBranchCommitLogNoCommitsInMerge() throws Exception {
ImmutableList<Change<GitRevision>> changes = newReader()
.changes(origin.resolve(firstCommitRef), origin.resolve("HEAD")).getChanges();
assertThat(changes).hasSize(2);
assertThat(changes.get(1).getMessage()).isEqualTo("Merge branch 'feature'\n");
assertThat(changes.get(1).getMessage()).contains("Merge branch 'feature'");
}

@Test
public void testChangesMergeNoop() throws Exception {
ImmutableList<? extends Change<?>> includedChanges = checkChangesMergeNoop(false);
assertThat(includedChanges.stream().map(Change::getMessage).collect(Collectors.toList()))
.containsExactly(
"Merge branch 'feature1'\n",
"feature1\n",
"main_branch_change\n");
List<String> msgList =
includedChanges.stream().map(Change::getMessage).collect(Collectors.toList());

assertThat(msgList).hasSize(3);
assertThat(msgList.get(0)).contains("Merge branch 'feature1'");
assertThat(msgList.get(1)).contains("feature1");
assertThat(msgList.get(2)).contains("main_branch_change");
}

@Test
public void testChangesMergeNoop_importNoopChanges() throws Exception {
ImmutableList<? extends Change<?>> includedChanges = checkChangesMergeNoop(true);
assertThat(includedChanges.stream().map(Change::getMessage).collect(Collectors.toList()))
.containsExactly(
"Merge branch 'feature1'\n",
"feature1\n",
"main_branch_change\n",
"change1\n",
"change2\n",
"change3\n",
"exclude1\n",
"Merge branch 'feature2'\n");
List<String> msgList =
includedChanges.stream().map(Change::getMessage).collect(Collectors.toList());
assertThat(msgList).hasSize(8);
assertThat(msgList.get(0)).contains("Merge branch 'feature2'");
assertThat(msgList.get(1)).contains("change3");
assertThat(msgList.get(2)).contains("change2");
assertThat(msgList.get(3)).contains("change1");
assertThat(msgList.get(4)).contains("Merge branch 'feature1'");
assertThat(msgList.get(5)).contains("feature1");
assertThat(msgList.get(6)).contains("exclude1");
assertThat(msgList.get(7)).contains("main_branch_change");

}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit ca76c0b

Please sign in to comment.