org.eclipse.jgit.api.MergeResult.MergeStatus Java Examples
The following examples show how to use
org.eclipse.jgit.api.MergeResult.MergeStatus.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UIGit.java From hop with Apache License 2.0 | 6 votes |
private boolean mergeBranch( String value, String mergeStrategy ) { try { ObjectId obj = git.getRepository().resolve( value ); MergeResult result = git.merge() .include( obj ) .setStrategy( MergeStrategy.get( mergeStrategy ) ) .call(); if ( result.getMergeStatus().isSuccessful() ) { showMessageBox( BaseMessages.getString( PKG, "Dialog.Success" ), BaseMessages.getString( PKG, "Dialog.Success" ) ); return true; } else { showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), result.getMergeStatus().toString() ); if ( result.getMergeStatus() == MergeStatus.CONFLICTING ) { result.getConflicts().keySet().forEach( path -> { checkout( path, Constants.HEAD, ".ours" ); checkout( path, getExpandedName( value, IVCS.TYPE_BRANCH ), ".theirs" ); } ); return true; } } } catch ( Exception e ) { showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() ); } return false; }
Example #2
Source File: GitCommitHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean workaroundBug356918(HttpServletRequest request, HttpServletResponse response, Exception e) throws ServletException, JSONException { if (e instanceof CheckoutConflictException) { JSONObject result = new JSONObject(); result.put(GitConstants.KEY_RESULT, MergeStatus.FAILED.name()); Map<String, MergeFailureReason> failingPaths = new HashMap<String, MergeFailureReason>(); String[] files = e.getMessage().split("\n"); //$NON-NLS-1$ for (int i = 1; i < files.length; i++) { // TODO: this is not always true, but it's a temporary // workaround failingPaths.put(files[i], MergeFailureReason.DIRTY_WORKTREE); } result.put(GitConstants.KEY_FAILING_PATHS, failingPaths); try { OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } catch (IOException e1) { e = e1; } } return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occurred when merging.", e.getCause())); }
Example #3
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetCloneAndPull() throws Exception { // see bug 339254 createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); String contentLocation = clone(workspaceId, project).getString(ProtocolConstants.KEY_CONTENT_LOCATION); JSONArray clonesArray = listClones(workspaceId, null); assertEquals(1, clonesArray.length()); Repository r = getRepositoryForContentLocation(contentLocation); // overwrite user settings, do not rebase when pulling, see bug 372489 StoredConfig cfg = r.getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REBASE, false); cfg.save(); // TODO: replace with RESTful API when ready, see bug 339114 Git git = Git.wrap(r); PullResult pullResult = git.pull().call(); assertEquals(pullResult.getMergeResult().getMergeStatus(), MergeStatus.ALREADY_UP_TO_DATE); assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState()); }
Example #4
Source File: GitMergeSquashTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testMergeSquashSelf() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // "git merge master" JSONObject merge = merge(gitHeadUri, Constants.MASTER, true); MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeStatus.ALREADY_UP_TO_DATE, mergeResult); }
Example #5
Source File: GitMergeTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testMergeSelf() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // "git merge master" JSONObject merge = merge(gitHeadUri, Constants.MASTER); MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeStatus.ALREADY_UP_TO_DATE, mergeResult); }
Example #6
Source File: PullTask.java From ant-git-tasks with Apache License 2.0 | 6 votes |
@Override public void doExecute() { try { PullCommand pullCommand = git.pull().setRebase(rebase); if (getProgressMonitor() != null) { pullCommand.setProgressMonitor(getProgressMonitor()); } setupCredentials(pullCommand); PullResult pullResult = pullCommand.call(); if (!pullResult.isSuccessful()) { FetchResult fetchResult = pullResult.getFetchResult(); GitTaskUtils.validateTrackingRefUpdates(MESSAGE_PULLED_FAILED, fetchResult.getTrackingRefUpdates()); MergeStatus mergeStatus = pullResult.getMergeResult().getMergeStatus(); if (!mergeStatus.isSuccessful()) { throw new BuildException(String.format(MESSAGE_PULLED_FAILED_WITH_STATUS, mergeStatus.name())); } } } catch (Exception e) { throw new GitBuildException(String.format(MESSAGE_PULLED_FAILED_WITH_URI, getUri()), e); } }
Example #7
Source File: InitDBBootApplication.java From singleton with Eclipse Public License 2.0 | 5 votes |
public void updateDBdata() throws InterruptedException { File file = ps.downloadDocBySsh(); ps.done(file); logger.info("end init translate data to db--------------------------------------"); ps.gitStatus(); while (ps.getGitProp().getCheckIntervalTime() > 60000) { Thread.sleep(ps.getGitProp().getCheckIntervalTime()); logger.info("----------------------beign pull status --------------------------"); logger.info("begin pull from remote"); PullResult pullRS = ps.gitpull(); logger.info("end pull from remote"); logger.info("--------------the pull status-" + pullRS.getMergeResult().getMergeStatus()); if (pullRS.isSuccessful() && !pullRS.getMergeResult().getMergeStatus().equals(MergeStatus.ALREADY_UP_TO_DATE)) { logger.info("remote translation files have updated!!!"); logger.info("begin update data to DB"); ps.done(file); logger.info("end updated data to DB"); } else if (pullRS.isSuccessful() && pullRS.getMergeResult().getMergeStatus().equals(MergeStatus.ALREADY_UP_TO_DATE)) { logger.info("remote translation file have not updated!!!"); } else { logger.error("remote translation file merged error"); file = ps.downloadDocBySsh(); ps.done(file); } } logger.info("------------------------------end done run----------------------------"); }
Example #8
Source File: GitMergeSquashTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testMergeSquashAlreadyUpToDate() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "change in master"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // "git add ." WebRequest request = GitAddTest.getPutGitIndexRequest(gitIndexUri); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertStatus(new StatusResult().setChanged(1), gitStatusUri); // "git merge master" JSONObject merge = merge(gitHeadUri, Constants.MASTER, true); MergeStatus mergeResult = MergeResult.MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, mergeResult); // status hasn't changed assertStatus(new StatusResult().setChanged(1), gitStatusUri); }
Example #9
Source File: GitMergeTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testMergeAlreadyUpToDate() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "change in master"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // "git add ." WebRequest request = GitAddTest.getPutGitIndexRequest(gitIndexUri); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertStatus(new StatusResult().setChanged(1), gitStatusUri); // "git merge master" JSONObject merge = merge(gitHeadUri, Constants.MASTER); MergeStatus mergeResult = MergeResult.MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, mergeResult); // status hasn't changed assertStatus(new StatusResult().setChanged(1), gitStatusUri); }
Example #10
Source File: GitMirrorTest.java From centraldogma with Apache License 2.0 | 4 votes |
@Test void remoteToLocal_merge() throws Exception { pushMirrorSettings(null, null); // Mirror an empty git repository, which will; // - Create /mirror_state.json // - Remove the sample files created by createProject(). mirroringService.mirror().join(); // Create a text file, modify it in two branches ('master' and 'fork') and merge 'fork' into 'master'. addToGitIndex("alphabets.txt", // 'c' and 'x' are missing. "a\nb\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\ny\nz\n"); git.commit().setMessage("Add alphabets.txt").call(); //// Create a new branch 'fork' and add the missing 'x'. git.checkout().setCreateBranch(true).setName("fork").call(); addToGitIndex("alphabets.txt", // Add the missing 'x'. "a\nb\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n"); final RevCommit commit1 = git.commit().setMessage("Add missing 'x'").call(); //// Check out 'master' and add the missing 'c'. git.checkout().setName("master").call(); addToGitIndex("alphabets.txt", // Add the missing 'c'. "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\ny\nz\n"); final RevCommit commit2 = git.commit().setMessage("Add missing 'c'").call(); //// Merge 'fork' into 'master' to create a merge commit. final MergeResult mergeResult = git.merge() .include(commit1.getId()) .setFastForward(FastForwardMode.NO_FF) .setMessage("Merge 'fork'").call(); //// Make sure the merge commit has been added. assertThat(mergeResult.getMergeStatus()).isEqualTo(MergeStatus.MERGED); final RevCommit lastCommit = git.log().all().call().iterator().next(); assertThat(lastCommit.getParentCount()).isEqualTo(2); assertThat(lastCommit.getParents()).containsExactlyInAnyOrder(commit1, commit2); // Run the mirror and ensure alphabets.txt contains all alphabets. mirroringService.mirror().join(); final Revision headRev = client.normalizeRevision(projName, REPO_FOO, Revision.HEAD).join(); final Entry<JsonNode> expectedMirrorState = expectedMirrorState(headRev, "/"); final Entry<String> expectedAlphabets = Entry.ofText( headRev, "/alphabets.txt", "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n"); assertThat(client.getFiles(projName, REPO_FOO, Revision.HEAD, "/**").join().values()) .containsExactlyInAnyOrder(expectedMirrorState, expectedAlphabets); }
Example #11
Source File: PullJob.java From orion.server with Eclipse Public License 1.0 | 4 votes |
private IStatus doPull(IProgressMonitor monitor) throws IOException, GitAPIException, CoreException { ProgressMonitor gitMonitor = new EclipseGitProgressTransformer(monitor); Repository db = null; try { db = FileRepositoryBuilder.create(GitUtils.getGitDir(path)); Git git = Git.wrap(db); PullCommand pc = git.pull(); pc.setProgressMonitor(gitMonitor); pc.setCredentialsProvider(credentials); pc.setTransportConfigCallback(new TransportConfigCallback() { @Override public void configure(Transport t) { credentials.setUri(t.getURI()); if (t instanceof TransportHttp && cookie != null) { HashMap<String, String> map = new HashMap<String, String>(); map.put(GitConstants.KEY_COOKIE, cookie.getName() + "=" + cookie.getValue()); ((TransportHttp) t).setAdditionalHeaders(map); } } }); PullResult pullResult = pc.call(); if (monitor.isCanceled()) { return new Status(IStatus.CANCEL, GitActivator.PI_GIT, "Cancelled"); } // handle result if (pullResult.isSuccessful()) { return Status.OK_STATUS; } FetchResult fetchResult = pullResult.getFetchResult(); IStatus fetchStatus = FetchJob.handleFetchResult(fetchResult); if (!fetchStatus.isOK()) { return fetchStatus; } MergeStatus mergeStatus = pullResult.getMergeResult().getMergeStatus(); if (!mergeStatus.isSuccessful()) return new Status(IStatus.ERROR, GitActivator.PI_GIT, mergeStatus.name()); } finally { if (db != null) { db.close(); } } return Status.OK_STATUS; }
Example #12
Source File: GitBranchTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testCreateTrackingBranch() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String branchesLocation = clone.getString(GitConstants.KEY_BRANCH); // overwrite user settings, do not rebase when pulling, see bug 372489 StoredConfig cfg = getRepositoryForContentLocation(cloneContentLocation).getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REBASE, false); cfg.save(); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); String gitRemoteUri = gitSection.optString(GitConstants.KEY_REMOTE); // create local branch tracking origin/master final String BRANCH_NAME = "a"; final String REMOTE_BRANCH = Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER; branch(branchesLocation, BRANCH_NAME, REMOTE_BRANCH); // modify, add, commit JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "some change"); addFile(testTxt); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // push ServerStatus pushStatus = push(gitRemoteUri, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(true, pushStatus.isOK()); // TODO: replace with RESTful API for git pull when available // try to pull - up to date status is expected Git git = Git.wrap(getRepositoryForContentLocation(cloneContentLocation)); PullResult pullResults = git.pull().call(); assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom()); assertEquals(MergeStatus.ALREADY_UP_TO_DATE, pullResults.getMergeResult().getMergeStatus()); assertNull(pullResults.getRebaseResult()); // checkout branch which was created a moment ago response = checkoutBranch(cloneLocation, BRANCH_NAME); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // TODO: replace with RESTful API for git pull when available // try to pull again - now fast forward update is expected pullResults = git.pull().call(); assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom()); assertEquals(MergeStatus.FAST_FORWARD, pullResults.getMergeResult().getMergeStatus()); assertNull(pullResults.getRebaseResult()); } }
Example #13
Source File: GitMergeSquashTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testMergeSquashRemovingFolders() throws Exception { // see org.eclipse.jgit.api.MergeCommandTest.testMergeRemovingFolders() createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); String folderChildrenLocation = folder.getString(ProtocolConstants.KEY_CHILDREN_LOCATION); String folderLocation = folder.getString(ProtocolConstants.KEY_LOCATION); JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); String folderName = "folder1"; request = getPostFilesRequest(folderLocation + "/", getNewDirJSON(folderName).toString(), folderName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject folder1 = getChild(folder, "folder1"); String fileName = "file1.txt"; request = getPostFilesRequest(folder1.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); fileName = "file2.txt"; request = getPostFilesRequest(folder1.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); folderName = "folder2"; request = getPostFilesRequest(folderLocation + "/", getNewDirJSON(folderName).toString(), folderName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject folder2 = getChild(folder, "folder2"); fileName = "file1.txt"; request = getPostFilesRequest(folder2.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); fileName = "file2.txt"; request = getPostFilesRequest(folder2.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); request = GitAddTest.getPutGitIndexRequest(gitIndexUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "folders and files", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); deleteFile(folder1); deleteFile(folder2); request = GitAddTest.getPutGitIndexRequest(gitIndexUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "removing folders", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONArray commitsArray = log(gitHeadUri); assertEquals(3, commitsArray.length()); JSONObject commit = commitsArray.getJSONObject(0); assertEquals("removing folders", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); String toMerge = commit.getString(ProtocolConstants.KEY_NAME); commit = commitsArray.getJSONObject(1); assertEquals("folders and files", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); String toCheckout = commit.getString(ProtocolConstants.KEY_NAME); Repository db1 = getRepositoryForContentLocation(cloneContentLocation); Git git = Git.wrap(db1); git.checkout().setName(toCheckout).call(); JSONObject merge = merge(gitHeadUri, toMerge, true); MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeStatus.FAST_FORWARD_SQUASHED, mergeResult); request = getGetRequest(folderChildrenLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText())); assertNull(getChildByName(children, "folder1")); assertNull(getChildByName(children, "folder2")); } }
Example #14
Source File: GitMergeTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testMergeRemovingFolders() throws Exception { // see org.eclipse.jgit.api.MergeCommandTest.testMergeRemovingFolders() createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); String folderChildrenLocation = folder.getString(ProtocolConstants.KEY_CHILDREN_LOCATION); String folderLocation = folder.getString(ProtocolConstants.KEY_LOCATION); JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); String folderName = "folder1"; request = getPostFilesRequest(folderLocation + "/", getNewDirJSON(folderName).toString(), folderName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject folder1 = getChild(folder, "folder1"); String fileName = "file1.txt"; request = getPostFilesRequest(folder1.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); fileName = "file2.txt"; request = getPostFilesRequest(folder1.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); folderName = "folder2"; request = getPostFilesRequest(folderLocation + "/", getNewDirJSON(folderName).toString(), folderName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject folder2 = getChild(folder, "folder2"); fileName = "file1.txt"; request = getPostFilesRequest(folder2.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); fileName = "file2.txt"; request = getPostFilesRequest(folder2.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); request = GitAddTest.getPutGitIndexRequest(gitIndexUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "folders and files", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); deleteFile(folder1); deleteFile(folder2); request = GitAddTest.getPutGitIndexRequest(gitIndexUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "removing folders", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONArray commitsArray = log(gitHeadUri); assertEquals(3, commitsArray.length()); JSONObject commit = commitsArray.getJSONObject(0); assertEquals("removing folders", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); String toMerge = commit.getString(ProtocolConstants.KEY_NAME); commit = commitsArray.getJSONObject(1); assertEquals("folders and files", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); String toCheckout = commit.getString(ProtocolConstants.KEY_NAME); Repository db1 = getRepositoryForContentLocation(cloneContentLocation); Git git = Git.wrap(db1); git.checkout().setName(toCheckout).call(); JSONObject merge = merge(gitHeadUri, toMerge); MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeStatus.FAST_FORWARD, mergeResult); request = getGetRequest(folderChildrenLocation); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText())); assertNull(getChildByName(children, "folder1")); assertNull(getChildByName(children, "folder2")); } }
Example #15
Source File: JGitOperator.java From verigreen with Apache License 2.0 | 4 votes |
private Pair<Boolean, String> checkResult( String branchToUpdate, String branchHead, Pair<Boolean, String> ret, MergeResult mergeResult) throws IOException { if (mergeResult.getMergeStatus().equals(MergeStatus.CONFLICTING) || mergeResult.getMergeStatus().equals(MergeStatus.FAILED)) { VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Merge conflicts for parent_branch:%s into:%s. rejecting commit", branchHead, branchToUpdate)); reset(_repo.getRef(branchToUpdate).getName()); } else if (mergeResult.getMergeStatus().equals(MergeStatus.ALREADY_UP_TO_DATE) || mergeResult.getMergeStatus().equals(MergeStatus.FAST_FORWARD)) { VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Merge not needed for parent_branch:%s into:%s", branchHead, branchToUpdate)); ret = new Pair<>(true, ""); } else if (mergeResult.getMergeStatus().equals(MergeStatus.MERGED_NOT_COMMITTED)) { String autoMergeMessage = createMessageAutoCommit(mergeResult); String commitId = commit(commited_By_Collector, email_Address, autoMergeMessage ); String adjustCommitId = commitId.substring(0,7) + "_" + commited_By_Collector; VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), String.format( "Verigreen merge for parent_branch:%s into:%s was not committed. Performing auto commit [%s]", branchHead, branchToUpdate, adjustCommitId)); ret = new Pair<>(true, adjustCommitId); }else if (mergeResult.getMergeStatus().equals(MergeStatus.MERGED)) { VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), "Merge was made after diverted branch with auto commit"); ret = new Pair<>(true, ""); new RestClientImpl().post(CollectorApi.getPostVerigreenNeededRequest(mergeResult.getNewHead().getName().substring(0, 7))); } return ret; }
Example #16
Source File: Pull.java From wandora with GNU General Public License v3.0 | 4 votes |
@Override public void execute(Wandora wandora, Context context) { try { Git git = getGit(); if(git != null) { if(isNotEmpty(getGitRemoteUrl())) { PullCommand pull = git.pull(); String user = getUsername(); if(user == null) { if(pullUI == null) { pullUI = new PullUI(); } pullUI.setUsername(getUsername()); pullUI.setPassword(getPassword()); pullUI.setRemoteUrl(getGitRemoteUrl()); pullUI.openInDialog(); if(pullUI.wasAccepted()) { setUsername(pullUI.getUsername()); setPassword(pullUI.getPassword()); // setGitRemoteUrl(pullUI.getRemoteUrl()); // pull.setRemote(pullUI.getRemoteUrl()); if(isNotEmpty(getUsername())) { CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( getUsername(), getPassword() ); pull.setCredentialsProvider(credentialsProvider); } } else { return; } } setDefaultLogger(); setLogTitle("Git pull"); log("Pulling changes from remote repository..."); PullResult result = pull.call(); FetchResult fetchResult = result.getFetchResult(); MergeResult mergeResult = result.getMergeResult(); MergeStatus mergeStatus = mergeResult.getMergeStatus(); String fetchResultMessages = fetchResult.getMessages(); if(isNotEmpty(fetchResultMessages)) { log(fetchResult.getMessages()); } log(mergeStatus.toString()); if(mergeStatus.equals(MergeStatus.MERGED)) { int a = WandoraOptionPane.showConfirmDialog(wandora, "Reload Wandora project after pull?", "Reload Wandora project after pull?", WandoraOptionPane.YES_NO_OPTION); if(a == WandoraOptionPane.YES_OPTION) { reloadWandoraProject(); } } log("Ready."); } else { log("Repository has no remote origin and can't be pulled. " + "Initialize repository by cloning remote repository to set the remote origin."); } } else { logAboutMissingGitRepository(); } } catch(GitAPIException gae) { log(gae.toString()); } catch(NoWorkTreeException nwte) { log(nwte.toString()); } catch(Exception e) { log(e); } setState(WAIT); }