Skip to content
Permalink
Browse files
vcs: make follow work with merge commits
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Aug 29, 2020
1 parent e954044 commit 8a7eb7724f093ca9c4692bd30a52e66b82c1c638
Showing with 52 additions and 0 deletions.
  1. +3 −0 vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java
  2. +49 −0 vcs/src/test/java/org/openjdk/skara/vcs/RepositoryTests.java
@@ -305,6 +305,9 @@ public List<CommitMetadata> follow(Path path, Hash from, Hash to) throws IOExcep
var delimiter = "#@!_-=&";
var cmd = new ArrayList<String>();
cmd.addAll(List.of("git", "log",
"-c",
"--no-patch",
"--full-history",
"--follow",
"--format=" + delimiter + "\n" + GitCommitMetadata.FORMAT,
"--topo-order",
@@ -2641,4 +2641,53 @@ void testFollow(VCS vcs) throws IOException {
assertEquals(List.of(third, second, first), hashes);
}
}

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

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

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

Files.write(readme, List.of("Hello, again!!"));
r.add(readme);
var second = r.commit("Update README", "duke", "duke@openjdk.java.net");

r.checkout(first);
Files.write(readme, List.of("Greetings, world"));
r.add(readme);
var third = r.commit("Update README concurrently", "duke", "duke@openjdk.java.net");

if (vcs == VCS.GIT) {
r.checkout(r.defaultBranch());
r.merge(third, "ours", Repository.FastForward.DISABLE);
} else if (vcs == VCS.HG) {
r.checkout(second);
r.merge(third, ":local", Repository.FastForward.DISABLE);
} else {
fail("Unexpected VCS: " + vcs);
}
Files.write(readme, List.of("Resolve merge"));
r.add(readme);
var merge = r.commit("Merge", "duke", "duke@openjdk.java.net");

Files.write(readme, List.of("Final update"));
r.add(readme);
var fourth = r.commit("Final README update", "duke", "duke@openjdk.java.net");

var commits = r.follow(readme);
var hashes = commits.stream().map(CommitMetadata::hash).collect(Collectors.toList());
assertEquals(5, hashes.size());
assertTrue(hashes.contains(first));
assertTrue(hashes.contains(second));
assertTrue(hashes.contains(third));
assertTrue(hashes.contains(merge));
assertTrue(hashes.contains(fourth));
}
}
}

1 comment on commit 8a7eb77

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 8a7eb77 Aug 29, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.