mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-10 18:43:05 +02:00
remove unnecessary handler from HgModifyCommand / move NoChangesMadeException to scm-core
This commit is contained in:
18
scm-core/src/main/java/sonia/scm/NoChangesMadeException.java
Normal file
18
scm-core/src/main/java/sonia/scm/NoChangesMadeException.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package sonia.scm;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
public class NoChangesMadeException extends BadRequestException {
|
||||
public NoChangesMadeException(Repository repository, String branch) {
|
||||
super(ContextEntry.ContextBuilder.entity(repository).build(), "no changes detected to branch " + branch);
|
||||
}
|
||||
|
||||
public NoChangesMadeException(Repository repository) {
|
||||
super(ContextEntry.ContextBuilder.entity(repository).build(), "no changes detected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return "40RaYIeeR1";
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import sonia.scm.BadRequestException;
|
||||
import sonia.scm.ConcurrentModificationException;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.NoChangesMadeException;
|
||||
import sonia.scm.repository.GitWorkdirFactory;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -68,10 +68,10 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
for (ModifyCommandRequest.PartialRequest r : request.getRequests()) {
|
||||
r.execute(this);
|
||||
}
|
||||
failIfNotChanged(NoChangesMadeException::new);
|
||||
failIfNotChanged(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch()));
|
||||
Optional<RevCommit> revCommit = doCommit(request.getCommitMessage(), request.getAuthor());
|
||||
push();
|
||||
return revCommit.orElseThrow(NoChangesMadeException::new).name();
|
||||
return revCommit.orElseThrow(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch())).name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,17 +156,6 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
public void move(String sourcePath, String targetPath) {
|
||||
|
||||
}
|
||||
|
||||
private class NoChangesMadeException extends BadRequestException {
|
||||
public NoChangesMadeException() {
|
||||
super(ContextEntry.ContextBuilder.entity(context.getRepository()).build(), "no changes detected to branch " + ModifyWorker.this.request.getBranch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return "40RaYIeeR1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String throwInternalRepositoryException(String message, Exception e) {
|
||||
|
||||
@@ -6,9 +6,10 @@ import com.aragost.javahg.commands.CommitCommand;
|
||||
import com.aragost.javahg.commands.ExecutionException;
|
||||
import com.aragost.javahg.commands.PushCommand;
|
||||
import com.aragost.javahg.commands.RemoveCommand;
|
||||
import com.aragost.javahg.commands.StatusCommand;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.NoChangesMadeException;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.util.WorkingCopy;
|
||||
|
||||
@@ -26,12 +27,10 @@ import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
public class HgModifyCommand implements ModifyCommand {
|
||||
|
||||
private final HgRepositoryHandler handler;
|
||||
private HgCommandContext context;
|
||||
private final HgWorkdirFactory workdirFactory;
|
||||
|
||||
public HgModifyCommand(HgRepositoryHandler handler, HgCommandContext context, HgWorkdirFactory workdirFactory) {
|
||||
this.handler = handler;
|
||||
public HgModifyCommand(HgCommandContext context, HgWorkdirFactory workdirFactory) {
|
||||
this.context = context;
|
||||
this.workdirFactory = workdirFactory;
|
||||
}
|
||||
@@ -115,7 +114,9 @@ public class HgModifyCommand implements ModifyCommand {
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (StatusCommand.on(workingRepository).lines().isEmpty()) {
|
||||
throw new NoChangesMadeException(context.getScmRepository());
|
||||
}
|
||||
CommitCommand.on(workingRepository).user(String.format("%s <%s>", request.getAuthor().getName(), request.getAuthor().getMail())).message(request.getCommitMessage()).execute();
|
||||
List<Changeset> execute = PushCommand.on(workingRepository).execute();
|
||||
return execute.get(0).getNode();
|
||||
|
||||
@@ -242,7 +242,7 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
|
||||
@Override
|
||||
public ModifyCommand getModifyCommand() {
|
||||
return new HgModifyCommand(handler, context, workdirFactory);
|
||||
return new HgModifyCommand(context, workdirFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.NoChangesMadeException;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.Person;
|
||||
@@ -35,7 +36,7 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||
when(hookManager.getCredentials()).thenReturn("SECRET:SECRET");
|
||||
when(hookManager.createUrl()).thenReturn("http://localhost");
|
||||
HgRepositoryEnvironmentBuilder environmentBuilder = new HgRepositoryEnvironmentBuilder(handler, hookManager);
|
||||
hgModifyCommand = new HgModifyCommand(handler, cmdContext, new SimpleHgWorkdirFactory(Providers.of(environmentBuilder), new WorkdirProvider()));
|
||||
hgModifyCommand = new HgModifyCommand(cmdContext, new SimpleHgWorkdirFactory(Providers.of(environmentBuilder), new WorkdirProvider()));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -159,11 +160,8 @@ public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||
hgModifyCommand.execute(request);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void shouldThrowIndexOutOfBoundExceptionIfRequestIsMissing() throws IOException {
|
||||
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||
request.setCommitMessage("I found the answer");
|
||||
request.setAuthor(new Person("Trillian Astra", "trillian@hitchhiker.com"));
|
||||
hgModifyCommand.execute(request);
|
||||
@Test(expected = NoChangesMadeException.class)
|
||||
public void shouldThrowNoChangesMadeExceptionIfEmptyLocalChangesetAfterRequest() {
|
||||
hgModifyCommand.execute(new ModifyCommandRequest());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user