Skip to content
Permalink
Browse files
672: Support pulling tags in checkout bot
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Sep 14, 2020
1 parent 4d2fa4a commit b86ed562b21979299c9a45adfd735a2aa88a0bb6
Showing 5 changed files with 69 additions and 14 deletions.
@@ -96,7 +96,7 @@ public Collection<WorkItem> run(Path scratch) {
new IllegalStateException("Git repository vanished from " + fromDir));
}
fromRepo.checkout(branch);
fromRepo.pull("origin", branch.name());
fromRepo.pull("origin", branch.name(), true);

var repoName = Path.of(from.getPath()).getFileName().toString();
var marksDir = scratch.resolve("checkout").resolve("marks").resolve(repoName);
@@ -66,9 +66,22 @@ default void add(Path... files) throws IOException {
default void remove(Path... files) throws IOException {
remove(Arrays.asList(files));
}
void pull() throws IOException;
void pull(String remote) throws IOException;
void pull(String remote, String refspec) throws IOException;

void pull(boolean includeTags) throws IOException;
default void pull() throws IOException {
pull(false);
}

void pull(String remote, boolean includeTags) throws IOException;
default void pull(String remote) throws IOException {
pull(remote, false);
}

void pull(String remote, String refspec, boolean includeTags) throws IOException;
default void pull(String remote, String refspec) throws IOException {
pull(remote, refspec, false);
}

void addremove() throws IOException;
void config(String section, String key, String value, boolean global) throws IOException;
default void config(String section, String key, String value) throws IOException {
@@ -1311,22 +1311,27 @@ public static Repository mirror(URI from, Path to) throws IOException {
}

@Override
public void pull() throws IOException {
pull(null, null);
public void pull(boolean includeTags) throws IOException {
pull(null, null, includeTags);
}

@Override
public void pull(String remote) throws IOException {
pull(remote, null);
public void pull(String remote, boolean includeTags) throws IOException {
pull(remote, null, includeTags);
}


@Override
public void pull(String remote, String refspec) throws IOException {
public void pull(String remote, String refspec, boolean includeTags) throws IOException {
var cmd = new ArrayList<String>();
cmd.add("git");
cmd.add("pull");
cmd.add("--recurse-submodules");
if (includeTags) {
cmd.add("--tags");
} else {
cmd.add("--no-tags");
}
if (remote != null) {
cmd.add(remote);
}
@@ -1251,17 +1251,18 @@ public static Repository clone(URI from, Path to, boolean isBare, Path seed) thr
}

@Override
public void pull() throws IOException {
pull(null, null);
public void pull(boolean includeTags) throws IOException {
pull(null, null, includeTags);
}

@Override
public void pull(String remote) throws IOException {
pull(remote, null);
public void pull(String remote, boolean includeTags) throws IOException {
pull(remote, null, includeTags);
}

@Override
public void pull(String remote, String refspec) throws IOException {
public void pull(String remote, String refspec, boolean includeTags) throws IOException {
// ignore includeTags, hg always pulls tags
var cmd = new ArrayList<String>();
cmd.addAll(List.of("hg", "pull", "--update"));
if (refspec != null) {
@@ -2690,4 +2690,40 @@ void testFollowMergeCommit(VCS vcs) throws IOException {
assertTrue(hashes.contains(fourth));
}
}

@ParameterizedTest
@EnumSource(VCS.class)
void testPull(VCS vcs) throws IOException {
try (var dir = new TemporaryDirectory()) {
var upstream = Repository.init(dir.path(), vcs);
var readme = dir.path().resolve("README");
Files.write(readme, List.of("Hello, readme!"));

upstream.add(readme);
var head = upstream.commit("Add README", "duke", "duke@openjdk.java.net");
upstream.tag(head, "1.0", "Added tag 1.0", "duke", "duke@openjdk.java.net");

try (var dir2 = new TemporaryDirectory()) {
var downstream = Repository.init(dir2.path(), vcs);

// note: forcing unix path separators for URI
var upstreamURI = URI.create("file:///" + dir.toString().replace('\\', '/'));
if (vcs == VCS.GIT) {
downstream.addRemote("origin", upstreamURI.toString());
downstream.pull("origin", "master");
assertEquals(1, downstream.commitMetadata().size());
assertEquals(head, downstream.commitMetadata().get(0).hash());
assertEquals(List.of(), downstream.tags());
downstream.pull("origin", "master", true);
assertEquals(List.of(new Tag("1.0")), downstream.tags());
} else {
downstream.addRemote("default", upstreamURI.toString());
downstream.pull("default");
assertEquals(2, downstream.commitMetadata().size());
assertEquals(head, downstream.commitMetadata().get(1).hash());
assertEquals(List.of(new Tag("tip"), new Tag("1.0")), downstream.tags());
}
}
}
}
}

1 comment on commit b86ed56

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on b86ed56 Sep 14, 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.