Skip to content
Permalink
Browse files
vcs: support setting dates for tags
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Aug 24, 2020
1 parent 71e10af commit 269027247e5c5778560d3031476dfd0ece4e57d3
Showing 4 changed files with 40 additions and 8 deletions.
@@ -111,7 +111,10 @@ Hash amend(String message,
String authorEmail,
String committerName,
String committerEmail) throws IOException;
Tag tag(Hash hash, String tagName, String message, String authorName, String authorEmail) throws IOException;
default Tag tag(Hash hash, String tagName, String message, String authorName, String authorEmail) throws IOException {
return tag(hash, tagName, message, authorName, authorEmail, null);
}
Tag tag(Hash hash, String tagName, String message, String authorName, String authorEmail, ZonedDateTime date) throws IOException;
Branch branch(Hash hash, String branchName) throws IOException;
void prune(Branch branch, String remote) throws IOException;
void delete(Branch b) throws IOException;
@@ -761,13 +761,17 @@ public Hash amend(String message, String authorName, String authorEmail, String
}

@Override
public Tag tag(Hash hash, String name, String message, String authorName, String authorEmail) throws IOException {
public Tag tag(Hash hash, String name, String message, String authorName, String authorEmail, ZonedDateTime date) throws IOException {
var cmd = Process.capture("git", "tag", "--annotate", "--message=" + message, name, hash.hex())
.workdir(dir)
.environ("GIT_AUTHOR_NAME", authorName)
.environ("GIT_AUTHOR_EMAIL", authorEmail)
.environ("GIT_COMMITTER_NAME", authorName)
.environ("GIT_COMMITTER_EMAIL", authorEmail);
if (date != null) {
cmd = cmd.environ("GIT_AUTHOR_DATE", date.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
cmd = cmd.environ("GIT_COMMITTER_DATE", date.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
}
try (var p = cmd.execute()) {
await(p);
}
@@ -660,15 +660,21 @@ public Hash amend(String message, String authorName, String authorEmail, String
}

@Override
public Tag tag(Hash hash, String name, String message, String authorName, String authorEmail) throws IOException {
public Tag tag(Hash hash, String name, String message, String authorName, String authorEmail, ZonedDateTime date) throws IOException {
var user = authorEmail != null ?
authorName + " <" + authorEmail + ">" :
authorName;
try (var p = capture("hg", "tag",
"--message", message,
"--user", user,
"--rev", hash.hex(),
name)) {
var cmd = new ArrayList<String>();
cmd.addAll(List.of("hg", "tag",
"--message", message,
"--user", user,
"--rev", hash.hex()));
if (date != null) {
cmd.add("--date");
cmd.add(date.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
}
cmd.add(name);
try (var p = capture(cmd)) {
await(p);
}

@@ -2596,4 +2596,23 @@ void testDeleteUntrackedFiles(VCS vcs) throws IOException {
assertTrue(paths.contains(readme));
}
}

@ParameterizedTest
@EnumSource(VCS.class)
void testTimestampOnTags(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 hash = r.commit("Add README", "duke", "duke@openjdk.java.net");
var date = ZonedDateTime.parse("2007-12-03T10:15:30+01:00");
var tag = r.tag(hash, "1.0", "Added tag 1.0", "duke", "duke@openjdk.org", date);
var annotated = r.annotate(tag);
assertTrue(annotated.isPresent());
assertEquals(date, annotated.get().date());
}
}
}

1 comment on commit 2690272

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 2690272 Aug 24, 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.