private boolean rebase( HttpServletRequest request, HttpServletResponse response, Repository db, String commitToRebase, String rebaseOperation) throws ServletException, JSONException, AmbiguousObjectException, IOException { JSONObject result = new JSONObject(); try { Git git = new Git(db); RebaseCommand rebase = git.rebase(); Operation operation; if (rebaseOperation != null) { operation = Operation.valueOf(rebaseOperation); } else { operation = Operation.BEGIN; } if (commitToRebase != null && !commitToRebase.isEmpty()) { ObjectId objectId = db.resolve(commitToRebase); rebase.setUpstream(objectId); } else if (operation.equals(Operation.BEGIN)) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Missing commit refId.", null)); } rebase.setOperation(operation); RebaseResult rebaseResult = rebase.call(); result.put(GitConstants.KEY_RESULT, rebaseResult.getStatus().name()); } catch (UnmergedPathsException e) { // this error should be handled by client, so return a proper status result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_UNMERGED_PATHS.name()); } catch (WrongRepositoryStateException e) { // this error should be handled by client, so return a proper status result.put( GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE.name()); } catch (IllegalArgumentException e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Invalid rebase operation.", e)); } catch (GitAPIException e) { // get cause and try to handle if (e.getCause() instanceof org.eclipse.jgit.errors.CheckoutConflictException) { // this error should be handled by client, so return a proper status result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_PENDING_CHANGES.name()); } else { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e)); } } OrionServlet.writeJSONResponse( request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; }
@Override @Port(name = "files", method = "saveFile") public boolean saveFile(String relativePath, byte[] data) { boolean result = true; // super.saveFile(relativePath, data); File f = new File(baseFolder.getAbsolutePath() + relativePath); if (f.exists()) { result = save(relativePath, data); /*String relativePathClean = relativePath; if (relativePath.startsWith("/")) { relativePathClean = relativePath.substring(relativePath.indexOf("/") + 1); }*/ commitRepository( " File " + relativePath + " saved ", " from site ", " [email protected] "); // TODO fix name and email try { // addFileToRepository(f); git.pull().call(); /*} catch (Exception e) { logger.error("error while unlock and commit git ", e); }*/ } catch (DetachedHeadException e) { try { git.revert().call(); save(relativePath + ".bak_" + new Date(), data); commitRepository( " File " + relativePath + " saved with conflict ", " name ", " email "); // TODO fix name and email UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider( (String) this.getDictionary().get("login"), (String) this.getDictionary().get("pass")); git.push().setCredentialsProvider(user).call(); return false; } catch (GitAPIException e1) { e1.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (NoHeadException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (TransportException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InvalidConfigurationException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (InvalidRemoteException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (CanceledException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (WrongRepositoryStateException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (RefNotFoundException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (GitAPIException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } try { UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider( (String) this.getDictionary().get("login"), (String) this.getDictionary().get("pass")); git.push().setCredentialsProvider(user).call(); return true; } catch (GitAPIException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } } return true; }