From 120416c4d62a67af3e989b1175f68df2f214048b Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Mon, 7 Oct 2019 13:49:43 +0200 Subject: [PATCH] pull modify changes from working copy to central repository so that mercurial hooks gets triggered --- .../scm/repository/spi/HgModifyCommand.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModifyCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModifyCommand.java index 7f9df4f60b..eaec861335 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModifyCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgModifyCommand.java @@ -4,7 +4,7 @@ import com.aragost.javahg.Changeset; import com.aragost.javahg.Repository; import com.aragost.javahg.commands.CommitCommand; import com.aragost.javahg.commands.ExecutionException; -import com.aragost.javahg.commands.PushCommand; +import com.aragost.javahg.commands.PullCommand; import com.aragost.javahg.commands.RemoveCommand; import com.aragost.javahg.commands.StatusCommand; import org.apache.commons.lang.StringUtils; @@ -118,14 +118,26 @@ public class HgModifyCommand implements ModifyCommand { throw new NoChangesMadeException(context.getScmRepository()); } CommitCommand.on(workingRepository).user(String.format("%s <%s>", request.getAuthor().getName(), request.getAuthor().getMail())).message(request.getCommitMessage()).execute(); - List execute = PushCommand.on(workingRepository).execute(); + List execute = pullModifyChangesToCentralRepository(request, workingCopy); return execute.get(0).getNode(); - } catch (IOException | ExecutionException e) { + } catch (ExecutionException e) { throwInternalRepositoryException("could not execute command on repository", e); return null; } } + private List pullModifyChangesToCentralRepository(ModifyCommandRequest request, WorkingCopy workingCopy) { + try { + com.aragost.javahg.commands.PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository()); + workdirFactory.configure(pullCommand); + return pullCommand.execute(workingCopy.getDirectory().getAbsolutePath()); + } catch (Exception e) { + throw new IntegrateChangesFromWorkdirException(context.getScmRepository(), + String.format("Could not pull modify changes from working copy to central repository", request.getBranch()), + e); + } + } + private String throwInternalRepositoryException(String message, Exception e) { throw new InternalRepositoryException(context.getScmRepository(), message, e); }