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

vcs: support setting dates for tags #735

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
@@ -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());
}
}
}