Skip to content

Hg merge fix #173

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

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 6 additions & 2 deletions java/com/google/copybara/hg/HgOrigin.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ public void checkout(HgRevision revision, Path workDir)
@Override
public ChangesResponse<HgRevision> changes(@Nullable HgRevision fromRef, HgRevision toRef)
throws RepoException {
String refRange = String.format("%s::%s",
fromRef == null ? "" : fromRef.getGlobalId(), toRef.getGlobalId());
String fromRefExpression = fromRef == null ? "null" : fromRef.getGlobalId();
// The "<from>::<to>" part is to filter out unrelated history. The "only()" bit is
// so we include commits merged in from a side branch.
String refRange =
String.format(
"only(%s::%s, %s)", fromRefExpression, toRef.getGlobalId(), fromRefExpression);

try {
ChangeReader reader = changeReaderBuilder().build();
Expand Down
2 changes: 1 addition & 1 deletion java/com/google/copybara/testing/FileSubjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static PathSubject assertThatPath(Path path) {
return assertAbout(PATH_SUBJECT_FACTORY).that(path);
}

public static class PathSubject extends Subject {
public static class PathSubject extends Subject<PathSubject, Path> {

private final Path actual;
private final Set<Path> allowedPaths = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LogSubjects {

private LogSubjects() {}

public static class LogSubject extends Subject {
public static class LogSubject extends Subject<LogSubject, TestingConsole> {

private final ArrayDeque<Message> messages;

Expand Down
7 changes: 1 addition & 6 deletions javatests/com/google/copybara/WorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public class WorkflowTest {
@Before
public void setup() throws Exception {
options = new OptionsBuilder();
options.setOutputRootToTmpDir();
authoring = "authoring.overwrite('" + DEFAULT_AUTHOR + "')";
includeReleaseNotes = false;
workdir = Files.createTempDirectory("workdir");
Expand Down Expand Up @@ -1932,7 +1933,6 @@ public void changeRequestEmptyChanges() throws Exception {
GitRepository origin = GitRepository.newRepo(/*verbose*/ true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();

options.setOutputRootToTmpDir();
String config =
"def after_all(ctx):\n"
+ " ctx.destination.message('after_all '"
Expand Down Expand Up @@ -1984,7 +1984,6 @@ public void reversibleCheckSymlinkError() throws Exception {
GitRepository origin = GitRepository.newRepo(/*verbose*/ true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();

options.setOutputRootToTmpDir();
String config = "core.workflow(\n"
+ " name = 'default',\n"
+ String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n",
Expand Down Expand Up @@ -2030,7 +2029,6 @@ public void reversibleCheckFiles() throws Exception {
GitRepository origin = GitRepository.newRepo(/*verbose*/ true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();

options.setOutputRootToTmpDir();
String config = "core.workflow(\n"
+ " name = 'default',\n"
+ String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n",
Expand Down Expand Up @@ -2117,8 +2115,6 @@ private void runGitDescribeVersionSemanticsForFilteredChanges(String mode)
GitRepository origin = GitRepository.newRepo(/*verbose*/ true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();

options.setOutputRootToTmpDir();

String config = "core.workflow(\n"
+ " name = 'default',\n"
+ String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n",
Expand Down Expand Up @@ -3395,7 +3391,6 @@ public void testFirstParentAlreadyImportedInNoFirstParent() throws Exception {
GitRepository origin = GitRepository.newRepo(/*verbose*/ true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();

options.setOutputRootToTmpDir();
options.setForce(false);
options.workflowOptions.initHistory = true;

Expand Down
40 changes: 20 additions & 20 deletions javatests/com/google/copybara/hg/HgOriginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ public void testTagCheckout() throws Exception {
public void testChanges() throws Exception {
ZonedDateTime beforeTime = ZonedDateTime.now(ZoneId.systemDefault()).minusSeconds(1);
String author = "Copy Bara <[email protected]>";
singleFileCommit(author, "zero", "foo.txt", "zero");
singleFileCommit(author, "one", "foo.txt", "one");
singleFileCommit(author, "two", "foo.txt", "two");
Path filePath = singleFileCommit(author, "three", "foo.txt", "three");
Path filePath = singleFileCommit(author, "two", "foo.txt", "two");

assertThat(Files.readAllBytes(filePath)).isEqualTo("three".getBytes(UTF_8));
assertThat(Files.readAllBytes(filePath)).isEqualTo("two".getBytes(UTF_8));

ImmutableList<Change<HgRevision>> changes =
newReader().changes(origin.resolve("1"), origin.resolve("tip")).getChanges();
newReader().changes(origin.resolve("0"), origin.resolve("tip")).getChanges();

assertThat(changes).hasSize(2);

assertThat(changes.get(0).getMessage()).isEqualTo("two");
assertThat(changes.get(1).getMessage()).isEqualTo("three");
assertThat(changes.get(0).getMessage()).isEqualTo("one");
assertThat(changes.get(1).getMessage()).isEqualTo("two");

for (Change<HgRevision> change : changes) {
assertThat(change.getAuthor().getEmail()).isEqualTo("[email protected]");
Expand All @@ -292,16 +292,16 @@ public void testFirstImportFromEmptyRepo() throws Exception {
@Test
public void testChangesNoFromRef() throws Exception {
String author = "Copy Bara <[email protected]>";
singleFileCommit(author, "zero", "foo.txt", "zero");
singleFileCommit(author, "one", "foo.txt", "one");
singleFileCommit(author, "two", "foo.txt", "two");
singleFileCommit(author, "three", "foo.txt", "three");

ImmutableList<Change<HgRevision>> changes =
newReader().changes(null, origin.resolve("1")).getChanges();

assertThat(changes).hasSize(2);
assertThat(changes.get(0).getMessage()).isEqualTo("one");
assertThat(changes.get(1).getMessage()).isEqualTo("two");
assertThat(changes.get(0).getMessage()).isEqualTo("zero");
assertThat(changes.get(1).getMessage()).isEqualTo("one");
}

@Test
Expand Down Expand Up @@ -339,8 +339,8 @@ public void testChangesUnrelatedRevisions() throws Exception {
@Test
public void testChangesToIsAncestor() throws Exception {
String author = "Copy Bara <[email protected]>";
singleFileCommit(author, "zero", "foo.txt", "zero");
singleFileCommit(author, "one", "foo.txt", "one");
singleFileCommit(author, "two", "foo.txt", "two");

ChangesResponse<HgRevision> changes =
newReader().changes(origin.resolve("tip"), origin.resolve("0"));
Expand All @@ -361,7 +361,7 @@ public void testUnknownChanges() throws Exception {
@Test
public void testChange() throws Exception {
String author = "Copy Bara <[email protected]>";
singleFileCommit(author, "one", "foo.txt", "one");
singleFileCommit(author, "zero", "foo.txt", "zero");

Change<HgRevision> change = newReader().change(origin.resolve("tip"));

Expand All @@ -370,7 +370,7 @@ public void testChange() throws Exception {

assertThat(change.getChangeFiles()).containsExactly("foo.txt");

assertThat(change.getMessage()).isEqualTo("one");
assertThat(change.getMessage()).isEqualTo("zero");
}

@Test
Expand All @@ -383,10 +383,10 @@ public void testUnknownChange() throws Exception {
@Test
public void testVisit() throws Exception {
String author = "Copy Bara <[email protected]>";
singleFileCommit(author, "zero", "foo.txt", "zero");
singleFileCommit(author, "one", "foo.txt", "one");
singleFileCommit(author, "two", "foo.txt", "two");
singleFileCommit(author, "three", "foo.txt", "three");
singleFileCommit(author, "four", "foo.txt", "four");

List<Change<?>> visited = new ArrayList<>();

Expand All @@ -395,22 +395,22 @@ public void testVisit() throws Exception {
origin.resolve("tip"),
input -> {
visited.add(input);
return input.firstLineMessage().equals("three")
return input.firstLineMessage().equals("two")
? VisitResult.TERMINATE
: VisitResult.CONTINUE;
});

assertThat(visited).hasSize(2);
assertThat(visited.get(0).firstLineMessage()).isEqualTo("four");
assertThat(visited.get(1).firstLineMessage()).isEqualTo("three");
assertThat(visited.get(0).firstLineMessage()).isEqualTo("three");
assertThat(visited.get(1).firstLineMessage()).isEqualTo("two");
}

@Test
public void testVisitOutsideRoot() throws Exception {
String author = "Copy Bara <[email protected]>";
singleFileCommit(author, "one", "foo/foo.txt", "one");
singleFileCommit(author, "two", "bar/foo.txt", "two");
singleFileCommit(author, "three", "foo/foo.txt", "three");
singleFileCommit(author, "zero", "foo/foo.txt", "zero");
singleFileCommit(author, "one", "bar/foo.txt", "one");
singleFileCommit(author, "two", "foo/foo.txt", "two");

originFiles = Glob.createGlob(ImmutableList.of("bar/**"));

Expand All @@ -423,7 +423,7 @@ public void testVisitOutsideRoot() throws Exception {
return VisitResult.CONTINUE;
});
assertThat(visited).hasSize(1);
assertThat(visited.get(0).firstLineMessage()).isEqualTo("two");
assertThat(visited.get(0).firstLineMessage()).isEqualTo("one");
}

@Test
Expand Down