This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git commit b57f866824927f936417ce28bebbb1b68e1e62d7 Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Wed May 20 09:38:43 2015 +0200 Add the ability to make a commit without a push for SCMs which allow to do this --- .../org/nuiton/scmwebeditor/git/GitConnection.java | 59 ++++++++++++---------- .../org/nuiton/scmwebeditor/git/GitProvider.java | 5 ++ .../org/nuiton/scmwebeditor/api/ScmProvider.java | 7 ++- .../org/nuiton/scmwebeditor/api/dto/CommitDto.java | 11 ++++ .../org/nuiton/scmwebeditor/svn/SvnProvider.java | 5 ++ .../scmwebeditor/uiweb/actions/EditAction.java | 7 +++ .../uiweb/actions/ScmWebEditorCommitAction.java | 7 +++ .../i18n/scmwebeditor-ui-web_en_GB.properties | 1 + .../i18n/scmwebeditor-ui-web_fr_FR.properties | 1 + .../webapp/WEB-INF/content/modificationViewer.jsp | 10 ++++ 10 files changed, 84 insertions(+), 29 deletions(-) diff --git a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java index 296baf8..12e2673 100644 --- a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java +++ b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitConnection.java @@ -393,40 +393,43 @@ public class GitConnection implements ScmConnection { } // push - PushCommand push = git.push(); - push.setRemote(addressGit); - push.setCredentialsProvider(credentials); + if (!dto.isCommitOnly()) { + PushCommand push = git.push(); + push.setRemote(addressGit); + push.setCredentialsProvider(credentials); - try { - push.call(); - } catch (GitAPIException e) { - - String logMessage = "Can not push"; + try { + push.call(); + } catch (GitAPIException e) { + + String logMessage = "Can not push"; + + if (e instanceof NoHeadException) { + logMessage = "Can not push : the Git repository has no HEAD reference"; + } else if (e instanceof UnmergedPathsException) { + logMessage = "Can not push : conflicts found (unmerged paths)"; + } else if (e instanceof ConcurrentRefUpdateException) { + logMessage = "Can not push : someone else is updating the HEAD or the branch"; + } else if (e instanceof WrongRepositoryStateException) { + logMessage = "Can not push : the repository is not in the right state"; + } else if (e instanceof RejectCommitException) { + logMessage = "Can not push : commit rejected"; + } - if (e instanceof NoHeadException) { - logMessage = "Can not push : the Git repository has no HEAD reference"; - } else if (e instanceof UnmergedPathsException) { - logMessage = "Can not push : conflicts found (unmerged paths)"; - } else if (e instanceof ConcurrentRefUpdateException) { - logMessage = "Can not push : someone else is updating the HEAD or the branch"; - } else if (e instanceof WrongRepositoryStateException) { - logMessage = "Can not push : the repository is not in the right state"; - } else if (e instanceof RejectCommitException) { - logMessage = "Can not push : commit rejected"; - } + if (log.isErrorEnabled()) { + log.error(logMessage, e); + } - if (log.isErrorEnabled()) { - log.error(logMessage, e); - } + if (e.getMessage().endsWith("not authorized")) { + resultDto.setError(RemoveResultDto.AUTH_ERROR); + } else { + resultDto.setError(RemoveResultDto.ERROR); + } - if (e.getMessage().endsWith("not authorized")) { - resultDto.setError(RemoveResultDto.AUTH_ERROR); - } else { - resultDto.setError(RemoveResultDto.ERROR); + return resultDto; } - - return resultDto; } + } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Can not open git local repository : " + localDirectory.getAbsolutePath(), e); diff --git a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitProvider.java b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitProvider.java index 4aeadcb..71a1e31 100644 --- a/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitProvider.java +++ b/swe-git/src/main/java/org/nuiton/scmwebeditor/git/GitProvider.java @@ -87,6 +87,11 @@ public class GitProvider implements ScmProvider { } @Override + public boolean supportsPush() { + return true; + } + + @Override public ScmConnection getConnection(String address, String pathToLocalRepos) { GitConnection gitConn = null; diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/ScmProvider.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/ScmProvider.java index f7961da..c3c445d 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/ScmProvider.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/ScmProvider.java @@ -45,6 +45,12 @@ public interface ScmProvider { List<String> listBranches(String address, String username, String password) throws OperationNotSupportedException; /** + * Tells whether the SCM allows to choose when the commits are pushed to the server + * @return true if the SCM supports a command to push the commits to the server + */ + boolean supportsPush(); + + /** * Gives the connection to the SCM * @param address the repository's address * @param pathToLocalRepos the folder which will be used to store one client's repositories @@ -52,7 +58,6 @@ public interface ScmProvider { */ ScmConnection getConnection(String address, String pathToLocalRepos); - /** * Tells whether the given address seems compatible with the SCM * @param address the repository's address diff --git a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/CommitDto.java b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/CommitDto.java index 3ff5723..074341e 100644 --- a/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/CommitDto.java +++ b/swe-scm-api/src/main/java/org/nuiton/scmwebeditor/api/dto/CommitDto.java @@ -20,6 +20,9 @@ public class CommitDto { /** the file to commit's address */ protected String address; + /** set to true for a commit without a push */ + private boolean commitOnly; + public String getUsername() { return username; @@ -68,4 +71,12 @@ public class CommitDto { public void setAddress(String address) { this.address = address; } + + public void setCommitOnly(boolean commitOnly) { + this.commitOnly = commitOnly; + } + + public boolean isCommitOnly() { + return commitOnly; + } } diff --git a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java index 9615068..d69f1ed 100644 --- a/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java +++ b/swe-svn/src/main/java/org/nuiton/scmwebeditor/svn/SvnProvider.java @@ -61,6 +61,11 @@ public class SvnProvider implements ScmProvider { } @Override + public boolean supportsPush() { + return false; + } + + @Override public ScmConnection getConnection(String address, String pathToLocalRepos) { SvnConnection svnConn = null; diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java index 85a46b7..b0b1e5f 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/EditAction.java @@ -50,6 +50,9 @@ public class EditAction extends ScmWebEditorMainAction { /** equals true if the SCM is able to use branches */ protected boolean scmSupportsBranches; + /** equals true if the SCM allows to choose when the commits are pushed to the server */ + protected boolean scmSupportsPush; + public String getSelectedBranch() { return selectedBranch; } @@ -59,6 +62,9 @@ public class EditAction extends ScmWebEditorMainAction { public void setScmSupportsBranches(boolean scmSupportsBranches) { this.scmSupportsBranches = scmSupportsBranches; } + public boolean isScmSupportsPush() { return scmSupportsPush; } + + public void setScmSupportsPush(boolean scmSupportsPush) { this.scmSupportsPush = scmSupportsPush; } /** * Execution of the edit action @@ -75,6 +81,7 @@ public class EditAction extends ScmWebEditorMainAction { ScmConnection scmConn = provider.getConnection(address, pathToLocalRepos); scmSupportsBranches = provider.supportsBranches(); + scmSupportsPush = provider.supportsPush(); format = scmConn.getFileName().substring(scmConn.getFileName().lastIndexOf(".") + 1); diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java index 2525968..3d28eb8 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/ScmWebEditorCommitAction.java @@ -102,6 +102,9 @@ public class ScmWebEditorCommitAction extends AbstractScmWebEditorAction impleme /** the number of the current revision */ protected String numRevision; + /** equals true if only a commit is requested, without a push */ + protected boolean commitOnly; + /** the HTTP request sent to the server */ protected transient HttpServletRequest request; @@ -176,6 +179,9 @@ public class ScmWebEditorCommitAction extends AbstractScmWebEditorAction impleme public void setBadLogin(boolean badLogin) { this.badLogin = badLogin; } + public boolean isCommitOnly() { return commitOnly; } + + public void setCommitOnly(boolean commitOnly) { this.commitOnly = commitOnly; } /** * Tells whether a RST file has a valid syntax @@ -280,6 +286,7 @@ public class ScmWebEditorCommitAction extends AbstractScmWebEditorAction impleme dto.setCommitMessage(commitMessage); dto.setForce(force); dto.setAddress(address); + dto.setCommitOnly(commitOnly); CommitResultDto resultDto = scmConn.commit(dto); diff --git a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties index 51dc3d2..a1d6e05 100644 --- a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties +++ b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties @@ -26,6 +26,7 @@ scm.loginButton=Login scm.logoutWait=Logout... scm.modificationViewer.betterUseJavascript=For a better use of SCMWebEditor please activate JavaScript. scm.modificationViewer.branch=Working on branch\: +scm.modificationViewer.commitOnly=Make a commit only (no push) scm.modificationViewer.noJavascript=Javascript is not activated. You can't only use Save and Quit or upload button. scm.modificationViewer.previewPosition=Preview's position\: scm.modificationViewer.previewPosition.below=Below diff --git a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties index 8aef259..f28223f 100644 --- a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties +++ b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties @@ -26,6 +26,7 @@ scm.loginButton=Connexion scm.logoutWait=Déconnexion... scm.modificationViewer.betterUseJavascript=Activer Javascript pour accéder à toutes les fonctionnalités. scm.modificationViewer.branch=Vous travaillez sur la branche \: +scm.modificationViewer.commitOnly=Faire un commit seulement (pas de push) scm.modificationViewer.noJavascript=Javascript est désactivé. Vous pouvez seulement utiliser les boutons sauvegarder et quitter, quitter ou ajouter un fichier. scm.modificationViewer.previewPosition=Position de l'aperçu \: scm.modificationViewer.previewPosition.below=En dessous diff --git a/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp b/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp index 3889bf1..d8efd2b 100644 --- a/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp +++ b/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp @@ -315,6 +315,16 @@ <div id="commitArea"> <s:textarea cols="60" label="%{scm.commitMessage} " name="commitMessage" title="%{scm.commitMessageTitle}"></s:textarea> + + <s:if test="scmSupportsPush"> + <input type="checkbox" name="commitOnly" id="commitOnly" value="true"/> + <label for="commitOnly"><s:text name="scm.modificationViewer.commitOnly"/></label> + + <script type="text/javascript"> + document.getElementById("commitMessage").style.height = "35px"; + </script> + + </s:if> </div> </div> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.