#9 Added command to leniently remove local tags for a release train.

This commit is contained in:
Oliver Gierke
2016-02-12 15:25:08 +01:00
parent a5daf60f8c
commit ee50568003
2 changed files with 32 additions and 9 deletions

View File

@@ -99,4 +99,9 @@ public class GitCommands implements CommandMarker {
git.push(iteration);
}
}
@CliCommand("git remove tags")
public void removeTags(@CliOption(key = "", mandatory = true) TrainIteration iteration) {
git.removeTags(iteration);
}
}

View File

@@ -144,12 +144,8 @@ public class GitOperations {
Project project = module.getProject();
ArtifactVersion artifactVersion = ArtifactVersion.of(module);
Tag tag = findTagFor(project, artifactVersion);
if (tag == null) {
throw new IllegalStateException(
String.format("No tag found for version %s of project %s, aborting.", artifactVersion, project));
}
Tag tag = findTagFor(project, artifactVersion).orElseThrow(() -> new IllegalStateException(
String.format("No tag found for version %s of project %s, aborting.", artifactVersion, project)));
try (Git git = new Git(getRepository(module.getProject()))) {
@@ -397,6 +393,29 @@ public class GitOperations {
});
}
public void removeTags(TrainIteration iteration) {
ExecutionUtils.run(iteration, module -> {
Project project = module.getProject();
ArtifactVersion artifactVersion = ArtifactVersion.of(module);
Optional<Tag> tag = findTagFor(project, artifactVersion);
if (!tag.isPresent()) {
logger.log(module, "No tag %s found project %s, skipping.", artifactVersion, project);
return;
}
try (Git git = new Git(getRepository(module.getProject()))) {
logger.log(module, "git tag -D %s", tag.get());
git.tagDelete().setTags(tag.get().toString()).call();
}
});
}
private Branch createMaintenanceBranch(ModuleIteration module) throws Exception {
try (Git git = new Git(getRepository(module.getProject()))) {
@@ -447,12 +466,11 @@ public class GitOperations {
* @return
* @throws IOException
*/
private Tag findTagFor(Project project, ArtifactVersion version) {
private Optional<Tag> findTagFor(Project project, ArtifactVersion version) {
return getTags(project).stream().//
filter(tag -> tag.toArtifactVersion().map(it -> it.equals(version)).orElse(false)).//
findFirst().orElseThrow(() -> new IllegalArgumentException(
String.format("No tag found for version %s of project %s!", version, project)));
findFirst();
}
private Repository getRepository(Project project) throws IOException {