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

hg: implement ReadOnlyRepository.isAncestor #730

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -697,7 +697,7 @@ public Hash mergeBase(Hash first, Hash second) throws IOException {

@Override
public boolean isAncestor(Hash ancestor, Hash descendant) throws IOException {
throw new RuntimeException("Not implemented yet");
return mergeBase(ancestor, descendant).equals(ancestor);
}

@Override
@@ -555,6 +555,34 @@ void testMergeBase(VCS vcs) throws IOException {
}
}

@ParameterizedTest
@EnumSource(VCS.class)
void testIsAncestor(VCS vcs) throws IOException {
try (var dir = new TemporaryDirectory()) {
var r = Repository.init(dir.path(), vcs);

var readme = dir.path().resolve("README");
Files.write(readme, List.of("Hello, readme!"));

r.add(readme);
var hash1 = r.commit("Add README", "duke", "duke@openjdk.java.net");

Files.write(readme, List.of("Another line"), WRITE, APPEND);
r.add(readme);
var hash2 = r.commit("Modify README", "duke", "duke@openjdk.java.net");

assertTrue(r.isAncestor(hash1, hash2));

r.checkout(hash1, false);
Files.write(readme, List.of("A conflicting line"), WRITE, APPEND);
r.add(readme);
var hash3 = r.commit("Branching README modification", "duke", "duke@openjdk.java.net");

assertTrue(r.isAncestor(hash1, hash3));
assertFalse(r.isAncestor(hash2, hash3));
}
}

@ParameterizedTest
@EnumSource(VCS.class)
void testRebase(VCS vcs) throws IOException {