List of usage examples for org.eclipse.jgit.lib StoredConfig setBoolean
public void setBoolean(final String section, final String subsection, final String name, final boolean value)
From source file:org.eclipse.orion.server.tests.servlets.git.GitResetTest.java
License:Open Source License
@Test @Ignore("see bug 339397") public void testResetAutocrlfTrue() throws Exception { // "git config core.autocrlf true" Git git = new Git(db); StoredConfig config = git.getRepository().getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, Boolean.TRUE);/*from w w w.j a v a2 s . c o m*/ config.save(); URI workspaceLocation = createWorkspace(getMethodName()); String projectName = getMethodName(); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); String projectId = project.getString(ProtocolConstants.KEY_ID); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); String gitCommitUri = gitSection.getString(GitConstants.KEY_COMMIT); // CRLF // TODO: don't create URIs out of thin air WebRequest request = getPutFileRequest(projectId + "/test.txt", "f" + "\r\n" + "older"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // "git add {path}" // TODO: don't create URIs out of thin air request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // commit request = GitCommitTest.getPostGitCommitRequest(gitCommitUri, "added new line - crlf", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // assert there is nothing to commit request = GitStatusTest.getGetGitStatusRequest(gitStatusUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject statusResponse = new JSONObject(response.getText()); GitStatusTest.assertStatusClean(statusResponse); // create new file String fileName = "new.txt"; request = getPostFilesRequest(projectId + "/", getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject file = new JSONObject(response.getText()); String location = file.optString(ProtocolConstants.KEY_LOCATION, null); assertNotNull(location); // LF request = getPutFileRequest(location, "i'm" + "\n" + "new"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // "git add ." request = GitAddTest.getPutGitIndexRequest(gitIndexUri /* stage all */); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // reset request = getPostGitIndexRequest(gitIndexUri /* reset all */, ResetType.MIXED); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); request = GitStatusTest.getGetGitStatusRequest(gitStatusUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); statusResponse = new JSONObject(response.getText()); JSONArray statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_ADDED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CHANGED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MISSING); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MODIFIED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_REMOVED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_UNTRACKED); assertEquals(1, statusArray.length()); }
From source file:org.eclipse.recommenders.snipmatch.GitSnippetRepository.java
License:Open Source License
private void configureGit() throws IOException { Git git = Git.open(gitFile);// www . j a va 2s . c o m StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", getRepositoryLocation()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.setString("remote", "origin", "pushUrl", pushUrl); // prevents trust anchor errors when pulling from eclipse.org config.setBoolean("http", null, "sslVerify", false); config.save(); }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public boolean configBranch(ServiceInvocationContext context, List<PathFragment> path, GitRef upstreamBranch, RemoteConfig remote, boolean rebase) { try {// w ww .j a va 2s .com RefNode node = (RefNode) GenericTreeStatefulService.getNodeByPathFor(path, null); Repository repository = node.getRepository(); StoredConfig config = repository.getConfig(); Ref ref; if (node instanceof Ref) { ref = node.getRef(); } else { // get remote branch String dst = Constants.R_REMOTES + remote.getName(); String remoteRefName = dst + "/" + upstreamBranch.getShortName(); ref = repository.getRef(remoteRefName); if (ref == null) { // doesn't exist, fetch it RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(upstreamBranch.getName(), remoteRefName); new Git(repository).fetch().setRemote(new URIish(remote.getUri()).toPrivateString()) .setRefSpecs(refSpec).call(); ref = repository.getRef(remoteRefName); } } String branchName = node.getRef().getName().substring(Constants.R_HEADS.length()); if (upstreamBranch.getName().length() > 0) { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE, upstreamBranch.getName()); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); } if (remote.getName().length() > 0) { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE, remote.getName()); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); } if (rebase) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, true); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE); } config.save(); return true; } catch (Exception e) { logger.debug(CommonPlugin.getInstance().getMessage("error"), path, e); context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } }
From source file:org.flowerplatform.web.git.operation.CheckoutOperation.java
License:Open Source License
public boolean execute() { ProgressMonitor monitor = ProgressMonitor .create(GitPlugin.getInstance().getMessage("git.checkout.monitor.title"), channel); try {// ww w. jav a2 s . co m monitor.beginTask( GitPlugin.getInstance().getMessage("git.checkout.monitor.message", new Object[] { name }), 4); monitor.setTaskName("Getting remote branch..."); Git git = new Git(repository); Ref ref; if (node instanceof Ref) { ref = (Ref) node; } else { // get remote branch String dst = Constants.R_REMOTES + remote.getName(); String remoteRefName = dst + "/" + upstreamBranch.getShortName(); ref = repository.getRef(remoteRefName); if (ref == null) { // doesn't exist, fetch it RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(upstreamBranch.getName(), remoteRefName); git.fetch().setRemote(new URIish(remote.getUri()).toPrivateString()).setRefSpecs(refSpec) .call(); ref = repository.getRef(remoteRefName); } } monitor.worked(1); monitor.setTaskName("Creating local branch..."); // create local branch git.branchCreate().setName(name).setStartPoint(ref.getName()) .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call(); if (!(node instanceof Ref)) { // save upstream configuration StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_MERGE, upstreamBranch.getName()); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REMOTE, remote.getName()); if (rebase) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REBASE, true); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REBASE); } config.save(); } monitor.worked(1); monitor.setTaskName("Creating working directory"); // create working directory for local branch File mainRepoFile = repository.getDirectory().getParentFile(); File wdirFile = new File(mainRepoFile.getParentFile(), GitUtils.WORKING_DIRECTORY_PREFIX + name); if (wdirFile.exists()) { GitPlugin.getInstance().getUtils().delete(wdirFile); } GitPlugin.getInstance().getUtils().run_git_workdir_cmd(mainRepoFile.getAbsolutePath(), wdirFile.getAbsolutePath()); monitor.worked(1); monitor.setTaskName("Checkout branch"); // checkout local branch Repository wdirRepo = GitPlugin.getInstance().getUtils().getRepository(wdirFile); git = new Git(wdirRepo); CheckoutCommand cc = git.checkout().setName(name).setForce(true); cc.call(); // show checkout result if (cc.getResult().getStatus() == CheckoutResult.Status.CONFLICTS) channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.checkout.checkoutConflicts.title"), GitPlugin.getInstance().getMessage("git.checkout.checkoutConflicts.message"), cc.getResult().getConflictList().toString(), DisplaySimpleMessageClientCommand.ICON_INFORMATION)); else if (cc.getResult().getStatus() == CheckoutResult.Status.NONDELETED) { // double-check if the files are still there boolean show = false; List<String> pathList = cc.getResult().getUndeletedList(); for (String path1 : pathList) { if (new File(wdirRepo.getWorkTree(), path1).exists()) { show = true; break; } } if (show) { channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.checkout.nonDeletedFiles.title"), GitPlugin.getInstance().getMessage("git.checkout.nonDeletedFiles.message", Repository.shortenRefName(name)), cc.getResult().getUndeletedList().toString(), DisplaySimpleMessageClientCommand.ICON_ERROR)); } } else if (cc.getResult().getStatus() == CheckoutResult.Status.OK) { if (ObjectId.isId(wdirRepo.getFullBranch())) channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.checkout.detachedHead.title"), GitPlugin.getInstance().getMessage("git.checkout.detachedHead.message"), DisplaySimpleMessageClientCommand.ICON_ERROR)); } monitor.worked(1); return true; } catch (Exception e) { channel.appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } finally { monitor.done(); } }
From source file:org.omegat.core.team.GITRemoteRepository.java
License:Open Source License
public void checkoutFullProject(String repositoryURL) throws Exception { Log.logInfoRB("GIT_START", "clone"); CloneCommand c = Git.cloneRepository(); c.setURI(repositoryURL);//ww w.j ava 2 s . co m c.setDirectory(localDirectory); try { c.call(); } catch (InvalidRemoteException e) { FileUtil.deleteTree(localDirectory); Throwable cause = e.getCause(); if (cause != null && cause instanceof org.eclipse.jgit.errors.NoRemoteRepositoryException) { BadRepositoryException bre = new BadRepositoryException( ((org.eclipse.jgit.errors.NoRemoteRepositoryException) cause).getLocalizedMessage()); bre.initCause(e); throw bre; } throw e; } repository = Git.open(localDirectory).getRepository(); new Git(repository).submoduleInit().call(); new Git(repository).submoduleUpdate().call(); //Deal with line endings. A normalized repo has LF line endings. //OmegaT uses line endings of OS for storing tmx files. //To do auto converting, we need to change a setting: StoredConfig config = repository.getConfig(); if ("\r\n".equals(FileUtil.LINE_SEPARATOR)) { //on windows machines, convert text files to CRLF config.setBoolean("core", null, "autocrlf", true); } else { //on Linux/Mac machines (using LF), don't convert text files //but use input format, unchanged. //NB: I don't know correct setting for OS'es like MacOS <= 9, // which uses CR. Git manual only speaks about converting from/to //CRLF, so for CR, you probably don't want conversion either. config.setString("core", null, "autocrlf", "input"); } config.save(); myCredentialsProvider.saveCredentials(); Log.logInfoRB("GIT_FINISH", "clone"); }
From source file:org.omegat.core.team2.impl.GITRemoteRepository2.java
License:Open Source License
@Override public void init(RepositoryDefinition repo, File dir, ProjectTeamSettings teamSettings) throws Exception { repositoryURL = repo.getUrl();// w w w .j ava2 s .c o m localDirectory = dir; String predefinedUser = repo.getOtherAttributes().get(new QName("gitUsername")); String predefinedPass = repo.getOtherAttributes().get(new QName("gitPassword")); String predefinedFingerprint = repo.getOtherAttributes().get(new QName("gitFingerprint")); ((GITCredentialsProvider) CredentialsProvider.getDefault()).setPredefinedCredentials(repositoryURL, predefinedUser, predefinedPass, predefinedFingerprint); ((GITCredentialsProvider) CredentialsProvider.getDefault()).setTeamSettings(teamSettings); File gitDir = new File(localDirectory, ".git"); if (gitDir.exists() && gitDir.isDirectory()) { // already cloned repository = Git.open(localDirectory).getRepository(); } else { Log.logInfoRB("GIT_START", "clone"); CloneCommand c = Git.cloneRepository(); c.setURI(repositoryURL); c.setDirectory(localDirectory); try { c.call(); } catch (InvalidRemoteException e) { if (localDirectory.exists()) { deleteDirectory(localDirectory); } Throwable cause = e.getCause(); if (cause != null && cause instanceof org.eclipse.jgit.errors.NoRemoteRepositoryException) { BadRepositoryException bre = new BadRepositoryException( ((org.eclipse.jgit.errors.NoRemoteRepositoryException) cause).getLocalizedMessage()); bre.initCause(e); throw bre; } throw e; } repository = Git.open(localDirectory).getRepository(); try (Git git = new Git(repository)) { git.submoduleInit().call(); git.submoduleUpdate().call(); } // Deal with line endings. A normalized repo has LF line endings. // OmegaT uses line endings of OS for storing tmx files. // To do auto converting, we need to change a setting: StoredConfig config = repository.getConfig(); if ("\r\n".equals(System.lineSeparator())) { // on windows machines, convert text files to CRLF config.setBoolean("core", null, "autocrlf", true); } else { // on Linux/Mac machines (using LF), don't convert text files // but use input format, unchanged. // NB: I don't know correct setting for OS'es like MacOS <= 9, // which uses CR. Git manual only speaks about converting from/to // CRLF, so for CR, you probably don't want conversion either. config.setString("core", null, "autocrlf", "input"); } config.save(); Log.logInfoRB("GIT_FINISH", "clone"); } // cleanup repository try (Git git = new Git(repository)) { git.reset().setMode(ResetType.HARD).call(); } }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.Clone.java
License:Apache License
public Optional<Git> execute() throws InvalidRemoteException { final Git git = Git.createRepository(repoDir, null); if (git != null) { final Collection<RefSpec> refSpecList; if (isMirror) { refSpecList = singletonList(new RefSpec("+refs/*:refs/*")); } else {//w w w . j a v a 2 s .c om refSpecList = emptyList(); } final Pair<String, String> remote = Pair.newPair("origin", origin); git.fetch(credentialsProvider, remote, refSpecList); final StoredConfig config = git.getRepository().getConfig(); config.setBoolean("remote", "origin", "mirror", true); try { config.save(); } catch (IOException e) { throw new RuntimeException(e); } git.syncRemote(remote); if (git.isKetchEnabled()) { git.convertRefTree(); git.updateLeaders(leaders); } git.setHeadAsInitialized(); return Optional.of(git); } return Optional.empty(); }
From source file:org.webcat.core.git.GitCloner.java
License:Open Source License
private Repository createWorkingCopyRepositoryIfNecessary(File location, File remoteDir) throws IOException { Repository wcRepository;/*from w w w . j a va 2 s . co m*/ try { wcRepository = RepositoryCache.open(FileKey.lenient(location, FS.DETECTED)); } catch (RepositoryNotFoundException e) { // Create the repository from scratch. if (!location.exists()) { location.mkdirs(); } InitCommand init = Git.init(); init.setDirectory(location); init.setBare(false); wcRepository = init.call().getRepository(); StoredConfig config = wcRepository.getConfig(); config.setBoolean("core", null, "bare", false); try { RefSpec refSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + "origin" + "/*"); RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); remoteConfig.addURI(new URIish(remoteDir.toString())); remoteConfig.addFetchRefSpec(refSpec); remoteConfig.update(config); } catch (URISyntaxException e2) { // Do nothing. } config.save(); } return wcRepository; }