mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
add HgModifyCommand / implement delete method
This commit is contained in:
@@ -0,0 +1,72 @@
|
|||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Changeset;
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import com.aragost.javahg.commands.CommitCommand;
|
||||||
|
import com.aragost.javahg.commands.PushCommand;
|
||||||
|
import com.aragost.javahg.commands.RemoveCommand;
|
||||||
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
|
import sonia.scm.repository.util.WorkingCopy;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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;
|
||||||
|
this.context = context;
|
||||||
|
this.workdirFactory = workdirFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(ModifyCommandRequest request) {
|
||||||
|
|
||||||
|
try (WorkingCopy<com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(context)) {
|
||||||
|
Repository workingRepository = workingCopy.getWorkingRepository();
|
||||||
|
request.getRequests().forEach(
|
||||||
|
partialRequest -> {
|
||||||
|
try {
|
||||||
|
partialRequest.execute(new Worker() {
|
||||||
|
@Override
|
||||||
|
public void delete(String toBeDeleted) {
|
||||||
|
RemoveCommand.on(workingRepository).execute(toBeDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create(String toBeCreated, File file, boolean overwrite) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modify(String path, File file) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void move(String sourcePath, String targetPath) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace(); // TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
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();
|
||||||
|
System.out.println(execute);
|
||||||
|
return execute.get(0).getNode();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,7 +66,8 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
Command.INCOMING,
|
Command.INCOMING,
|
||||||
Command.OUTGOING,
|
Command.OUTGOING,
|
||||||
Command.PUSH,
|
Command.PUSH,
|
||||||
Command.PULL
|
Command.PULL,
|
||||||
|
Command.MODIFY
|
||||||
);
|
);
|
||||||
//J+
|
//J+
|
||||||
|
|
||||||
@@ -77,10 +78,11 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
HgRepositoryServiceProvider(HgRepositoryHandler handler,
|
HgRepositoryServiceProvider(HgRepositoryHandler handler,
|
||||||
HgHookManager hookManager, Repository repository)
|
HgHookManager hookManager, Repository repository, HgWorkdirFactory workdirFactory)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.workdirFactory = workdirFactory;
|
||||||
this.repositoryDirectory = handler.getDirectory(repository.getId());
|
this.repositoryDirectory = handler.getDirectory(repository.getId());
|
||||||
this.context = new HgCommandContext(hookManager, handler, repository,
|
this.context = new HgCommandContext(hookManager, handler, repository,
|
||||||
repositoryDirectory);
|
repositoryDirectory);
|
||||||
@@ -238,6 +240,11 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
return new HgPushCommand(handler, context, repository);
|
return new HgPushCommand(handler, context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModifyCommand getModifyCommand() {
|
||||||
|
return new HgModifyCommand(handler, context, workdirFactory);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -287,4 +294,6 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private File repositoryDirectory;
|
private File repositoryDirectory;
|
||||||
|
|
||||||
|
private final HgWorkdirFactory workdirFactory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,15 +47,17 @@ import sonia.scm.repository.Repository;
|
|||||||
public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
private HgRepositoryHandler handler;
|
private final HgRepositoryHandler handler;
|
||||||
private HgHookManager hookManager;
|
private final HgHookManager hookManager;
|
||||||
|
private final HgWorkdirFactory workdirFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public HgRepositoryServiceResolver(HgRepositoryHandler handler,
|
public HgRepositoryServiceResolver(HgRepositoryHandler handler,
|
||||||
HgHookManager hookManager)
|
HgHookManager hookManager, HgWorkdirFactory workdirFactory)
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.hookManager = hookManager;
|
this.hookManager = hookManager;
|
||||||
|
this.workdirFactory = workdirFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,7 +65,7 @@ public class HgRepositoryServiceResolver implements RepositoryServiceResolver
|
|||||||
HgRepositoryServiceProvider provider = null;
|
HgRepositoryServiceProvider provider = null;
|
||||||
|
|
||||||
if (HgRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
if (HgRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
||||||
provider = new HgRepositoryServiceProvider(handler, hookManager, repository);
|
provider = new HgRepositoryServiceProvider(handler, hookManager, repository, workdirFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider;
|
return provider;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import com.google.inject.util.Providers;
|
||||||
|
import org.junit.Test;
|
||||||
|
import sonia.scm.repository.HgHookManager;
|
||||||
|
import sonia.scm.repository.Person;
|
||||||
|
import sonia.scm.repository.util.WorkdirProvider;
|
||||||
|
import sonia.scm.web.HgRepositoryEnvironmentBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class HgModifyCommandTest extends AbstractHgCommandTestBase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRemoveFiles() throws IOException {
|
||||||
|
HgHookManager hookManager = mock(HgHookManager.class);
|
||||||
|
when(hookManager.getChallenge()).thenReturn("CHALLENGE");
|
||||||
|
when(hookManager.getCredentials()).thenReturn("SECRET:SECRET");
|
||||||
|
when(hookManager.createUrl()).thenReturn("http://localhost");
|
||||||
|
HgRepositoryEnvironmentBuilder environmentBuilder = new HgRepositoryEnvironmentBuilder(handler, hookManager);
|
||||||
|
|
||||||
|
HgModifyCommand hgModifyCommand = new HgModifyCommand(handler, cmdContext, new SimpleHgWorkdirFactory(Providers.of(environmentBuilder), new WorkdirProvider()));
|
||||||
|
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||||
|
request.addRequest(new ModifyCommandRequest.DeleteFileRequest("a.txt"));
|
||||||
|
request.setCommitMessage("this is great");
|
||||||
|
request.setAuthor(new Person("Arthur Dent", "dent@hitchhiker.com"));
|
||||||
|
|
||||||
|
String result = hgModifyCommand.execute(request);
|
||||||
|
|
||||||
|
assertThat(cmdContext.open().tip().getNode()).isEqualTo(result);
|
||||||
|
cmdContext.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user