mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-22 22:50:11 +01:00
Strip 'Error:' from hg error messages
This commit is contained in:
@@ -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()),
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user