List of usage examples for org.eclipse.jgit.lib Repository getConfig
@NonNull public abstract StoredConfig getConfig();
From source file:org.eclipse.egit.core.test.GitProjectSetCapabilityTest.java
License:Open Source License
private File createRepository(IPath location, String url, String branch) throws Exception { File gitDirectory = new File(location.toFile(), Constants.DOT_GIT); Repository repo = new FileRepository(gitDirectory); repo.getConfig().setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", ConfigConstants.CONFIG_KEY_URL, url);/*from ww w . j ava 2s . c om*/ repo.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE, "origin"); repo.create(); repo.close(); Git git = new Git(repo); git.add().addFilepattern(".").call(); git.commit().setMessage("initial").call(); if (!branch.equals("master")) git.checkout().setName(branch).setCreateBranch(true).call(); pathsToClean.add(gitDirectory); return gitDirectory; }
From source file:org.eclipse.egit.core.test.op.CloneOperationTest.java
License:Open Source License
@Test public void testClone() throws Exception { URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString()); CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0); clop.run(null);//from ww w. j ava 2 s . co m Repository clonedRepo = new FileRepository(new File(workdir2, Constants.DOT_GIT)); assertEquals("", uri.toString(), clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "url")); assertEquals("", "+refs/heads/*:refs/remotes/origin/*", clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch")); File file = new File(workdir2, "file1.txt"); assertTrue(file.exists()); }
From source file:org.eclipse.egit.core.test.op.CloneOperationTest.java
License:Open Source License
@Test public void testConfigurePushAfterCloneTask() throws Exception { URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString()); CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0); clop.addPostCloneTask(new ConfigurePushAfterCloneTask("origin", "HEAD:refs/for/master", new URIish("file:///pushtarget"))); clop.run(null);//from w w w. j ava 2 s . c o m Repository clonedRepo = new FileRepository(new File(workdir2, Constants.DOT_GIT)); assertEquals("", "HEAD:refs/for/master", clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "push")); assertEquals("", "file:///pushtarget", clonedRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "pushurl")); }
From source file:org.eclipse.egit.core.test.op.CloneOperationTest.java
License:Open Source License
@Test public void testConfigureFetchAfterCloneTask() throws Exception { createNoteInOrigin();// ww w.ja va2s .c o m URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString()); CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0); clop.addPostCloneTask(new ConfigureFetchAfterCloneTask("origin", "refs/notes/review:refs/notes/review")); clop.run(null); Repository clonedRepo = new FileRepository(new File(workdir2, Constants.DOT_GIT)); assertTrue(clonedRepo.getConfig().getStringList(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch")[1] .equals("refs/notes/review:refs/notes/review")); Git clonedGit = new Git(clonedRepo); assertEquals(1, clonedGit.notesList().setNotesRef("refs/notes/review").call().size()); }
From source file:org.eclipse.egit.gitflow.op.InitOperationTest.java
License:Open Source License
private void assertPrefixEquals(String expected, String key, Repository repo) { assertEquals("Unexpected value for key " + key + ", config: " + repo.getConfig().toText(), expected, getPrefix(repo, key));/* w w w. j a v a2s . c o m*/ }
From source file:org.eclipse.egit.gitflow.op.InitOperationTest.java
License:Open Source License
private void assertBranchEquals(String expected, String key, Repository repo) { assertEquals("Unexpected branch in: " + repo.getConfig().toText(), expected, getBranch(repo, key)); }
From source file:org.eclipse.egit.gitflow.op.InitOperationTest.java
License:Open Source License
private String getPrefix(Repository repository, String prefixName) { StoredConfig config = repository.getConfig(); return config.getString(GITFLOW_SECTION, PREFIX_SECTION, prefixName); }
From source file:org.eclipse.egit.gitflow.op.InitOperationTest.java
License:Open Source License
private String getBranch(Repository repository, String branch) { StoredConfig config = repository.getConfig(); return config.getString(GITFLOW_SECTION, BRANCH_SECTION, branch); }
From source file:org.eclipse.egit.internal.mylyn.ui.commit.TaskReferenceFactory.java
License:Open Source License
private static String getRepoUrl(Repository repo) { String configuredUrl = repo.getConfig().getString(BUGTRACK_SECTION, null, BUGTRACK_URL); String originUrl = repo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL); return configuredUrl != null ? configuredUrl : originUrl; }
From source file:org.eclipse.egit.ui.internal.actions.CommitAction.java
License:Open Source License
@Override public void execute(IAction act) { // let's see if there is any dirty editor around and // ask the user if they want to save or abort if (!PlatformUI.getWorkbench().saveAllEditors(true)) { return;/* w w w . ja v a2s.c om*/ } resetState(); try { buildIndexHeadDiffList(); } catch (IOException e) { handle(new TeamException(UIText.CommitAction_errorComputingDiffs, e), UIText.CommitAction_errorDuringCommit, UIText.CommitAction_errorComputingDiffs); return; } catch (CoreException e) { handle(new TeamException(UIText.CommitAction_errorComputingDiffs, e), UIText.CommitAction_errorDuringCommit, UIText.CommitAction_errorComputingDiffs); return; } Repository[] repos = getRepositoriesFor(getProjectsForSelectedResources()); Repository repository = null; amendAllowed = repos.length == 1; for (Repository repo : repos) { repository = repo; RepositoryState state = repo.getRepositoryState(); // currently we don't support committing a merge commit if (state == RepositoryState.MERGING_RESOLVED || !state.canCommit()) { MessageDialog.openError(getTargetPart().getSite().getShell(), UIText.CommitAction_cannotCommit, NLS.bind(UIText.CommitAction_repositoryState, state.getDescription())); return; } } loadPreviousCommit(); if (files.isEmpty()) { if (amendAllowed && previousCommit != null) { boolean result = MessageDialog.openQuestion(getTargetPart().getSite().getShell(), UIText.CommitAction_noFilesToCommit, UIText.CommitAction_amendCommit); if (!result) return; amending = true; } else { MessageDialog.openWarning(getTargetPart().getSite().getShell(), UIText.CommitAction_noFilesToCommit, UIText.CommitAction_amendNotPossible); return; } } String author = null; String committer = null; if (repository != null) { final RepositoryConfig config = repository.getConfig(); author = config.getAuthorName(); final String authorEmail = config.getAuthorEmail(); author = author + " <" + authorEmail + ">"; //$NON-NLS-1$ //$NON-NLS-2$ committer = config.getCommitterName(); final String committerEmail = config.getCommitterEmail(); committer = committer + " <" + committerEmail + ">"; //$NON-NLS-1$ //$NON-NLS-2$ } CommitDialog commitDialog = new CommitDialog(getTargetPart().getSite().getShell()); commitDialog.setAmending(amending); commitDialog.setAmendAllowed(amendAllowed); commitDialog.setFileList(files); commitDialog.setPreselectedFiles(getSelectedFiles()); commitDialog.setAuthor(author); commitDialog.setCommitter(committer); if (previousCommit != null) { commitDialog.setPreviousCommitMessage(previousCommit.getMessage()); PersonIdent previousAuthor = previousCommit.getAuthor(); commitDialog .setPreviousAuthor(previousAuthor.getName() + " <" + previousAuthor.getEmailAddress() + ">"); //$NON-NLS-1$ //$NON-NLS-2$ } if (commitDialog.open() != IDialogConstants.OK_ID) return; final CommitOperation commitOperation = new CommitOperation(commitDialog.getSelectedFiles(), notIndexed, notTracked, commitDialog.getAuthor(), commitDialog.getCommitter(), commitDialog.getCommitMessage()); if (commitDialog.isAmending()) { commitOperation.setAmending(true); commitOperation.setPreviousCommit(previousCommit); commitOperation.setRepos(repos); } String jobname = UIText.CommitAction_CommittingChanges; Job job = new Job(jobname) { @Override protected IStatus run(IProgressMonitor monitor) { try { commitOperation.execute(monitor); for (IProject proj : getProjectsForSelectedResources()) { RepositoryMapping.getMapping(proj).fireRepositoryChanged(); } } catch (CoreException e) { return Activator.createErrorStatus(UIText.CommitAction_CommittingFailed, e); } finally { GitLightweightDecorator.refresh(); } return Status.OK_STATUS; } }; job.setUser(true); job.schedule(); }