Strip 'Error:' from hg error messages

This commit is contained in:
René Pfeuffer
2020-11-12 13:46:36 +01:00
parent a479fcbfe1
commit f8219305a3
2 changed files with 21 additions and 1 deletions

View File

@@ -39,9 +39,12 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.regex.Pattern;
public class HgModifyCommand implements ModifyCommand {
static final Pattern HG_MESSAGE_PATTERN = Pattern.compile(".*\\[SCM\\](?: Error:)? (.*)");
private HgCommandContext context;
private final HgWorkingCopyFactory workingCopyFactory;
@@ -115,7 +118,9 @@ public class HgModifyCommand implements ModifyCommand {
workingCopyFactory.configure(pullCommand);
return pullCommand.execute(workingCopy.getDirectory().getAbsolutePath());
} catch (ExecutionException e) {
throw IntegrateChangesFromWorkdirException.forMessage(context.getScmRepository(), e.getMessage());
throw IntegrateChangesFromWorkdirException
.withPattern(HG_MESSAGE_PATTERN)
.forMessage(context.getScmRepository(), e.getMessage());
} catch (IOException e) {
throw new InternalRepositoryException(context.getScmRepository(),
String.format("Could not pull modify changes from working copy to central repository for branch %s", request.getBranch()),

View File

@@ -42,6 +42,7 @@ import sonia.scm.web.HgRepositoryEnvironmentBuilder;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.regex.Matcher;
import static org.assertj.core.api.Assertions.assertThat;
@@ -186,4 +187,18 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
public void shouldThrowNoChangesMadeExceptionIfEmptyLocalChangesetAfterRequest() {
hgModifyCommand.execute(new ModifyCommandRequest());
}
@Test
public void shouldExtractSimpleMessage() {
Matcher matcher = HgModifyCommand.HG_MESSAGE_PATTERN.matcher("[SCM] This is a simple message");
matcher.matches();
assertThat(matcher.group(1)).isEqualTo("This is a simple message");
}
@Test
public void shouldExtractErrorMessage() {
Matcher matcher = HgModifyCommand.HG_MESSAGE_PATTERN.matcher("[SCM] Error: This is an error message");
matcher.matches();
assertThat(matcher.group(1)).isEqualTo("This is an error message");
}
}