List of usage examples for org.eclipse.jgit.lib Constants DOT_GIT
String DOT_GIT
To view the source code for org.eclipse.jgit.lib Constants DOT_GIT.
Click Source Link
From source file:org.eclipse.egit.ui.gitflow.InitHandlerTest.java
License:Open Source License
private TestRepository createAndShare(String projectName) throws Exception { IProgressMonitor progressMonitor = new NullProgressMonitor(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); project.create(progressMonitor);/* w ww .ja v a 2 s . c om*/ project.open(progressMonitor); TestUtil.waitForJobs(50, 5000); File gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT); TestRepository testRepository = new TestRepository(gitDir); testRepository.connect(project.getProject()); TestUtil.waitForJobs(50, 5000); return testRepository; }
From source file:org.eclipse.egit.ui.internal.clone.GitImportWizard.java
License:Open Source License
private Repository getTargetRepository() { if (existingRepo != null) return existingRepo; else//w w w . jav a 2s .c o m try { return org.eclipse.egit.core.Activator.getDefault().getRepositoryCache() .lookupRepository(new File(cloneDestination.getDestinationFile(), Constants.DOT_GIT)); } catch (IOException e) { Activator.error("Error looking up repository at " + cloneDestination.getDestinationFile(), e); //$NON-NLS-1$ return null; } }
From source file:org.eclipse.egit.ui.internal.components.RepositorySelectionPage.java
License:Open Source License
/** * Create repository selection page, allowing user specifying URI or * (optionally) choosing from preconfigured remotes list. * <p>/*from ww w.j a v a 2 s . co m*/ * Wizard page is created without image, just with text description. * * @param sourceSelection * true if dialog is used for source selection; false otherwise * (destination selection). This indicates appropriate text * messages. * @param configuredRemotes * list of configured remotes that user may select as an * alternative to manual URI specification. Remotes appear in * given order in GUI, with * {@value Constants#DEFAULT_REMOTE_NAME} as the default choice. * List may be null or empty - no remotes configurations appear * in this case. Note that the provided list may be changed by * this constructor. * @param presetUri * the pre-set URI, may be null */ public RepositorySelectionPage(final boolean sourceSelection, final List<RemoteConfig> configuredRemotes, String presetUri) { super(RepositorySelectionPage.class.getName()); this.uri = new URIish(); this.sourceSelection = sourceSelection; String preset = presetUri; if (presetUri == null) { Clipboard clippy = new Clipboard(Display.getCurrent()); String text = (String) clippy.getContents(TextTransfer.getInstance()); try { if (text != null) { text = text.trim(); int index = text.indexOf(' '); if (index > 0) text = text.substring(0, index); URIish u = new URIish(text); if (Transport.canHandleProtocol(u, FS.DETECTED)) { if (Protocol.GIT.handles(u) || Protocol.SSH.handles(u) || text.endsWith(Constants.DOT_GIT)) preset = text; } } } catch (URISyntaxException e) { // ignore, preset is null } clippy.dispose(); } this.presetUri = preset; this.configuredRemotes = getUsableConfigs(configuredRemotes); this.remoteConfig = selectDefaultRemoteConfig(); selection = RepositorySelection.INVALID_SELECTION; if (sourceSelection) { setTitle(UIText.RepositorySelectionPage_sourceSelectionTitle); setDescription(UIText.RepositorySelectionPage_sourceSelectionDescription); } else { setTitle(UIText.RepositorySelectionPage_destinationSelectionTitle); setDescription(UIText.RepositorySelectionPage_destinationSelectionDescription); } }
From source file:org.eclipse.egit.ui.internal.merge.GitMergeEditorInput.java
License:Open Source License
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { final Set<IFile> files = new HashSet<IFile>(); List<IContainer> folders = new ArrayList<IContainer>(); Set<IProject> projects = new HashSet<IProject>(); // collect all projects and sort the selected // resources into files and folders; skip // ignored resources for (IResource res : resources) { projects.add(res.getProject());/*from ww w .j a v a 2 s.com*/ if (Team.isIgnoredHint(res)) continue; if (res.getType() == IResource.FILE) files.add((IFile) res); else folders.add((IContainer) res); } if (monitor.isCanceled()) throw new InterruptedException(); // make sure all resources belong to the same repository Repository repo = null; for (IProject project : projects) { RepositoryMapping map = RepositoryMapping.getMapping(project); if (repo != null && repo != map.getRepository()) throw new InvocationTargetException( new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository)); repo = map.getRepository(); } if (repo == null) throw new InvocationTargetException( new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository)); if (monitor.isCanceled()) throw new InterruptedException(); // collect all file children of the selected folders IResourceVisitor fileCollector = new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (Team.isIgnoredHint(resource)) return false; if (resource.getType() == IResource.FILE) { files.add((IFile) resource); } return true; } }; for (IContainer cont : folders) { try { cont.accept(fileCollector); } catch (CoreException e) { // ignore here } } if (monitor.isCanceled()) throw new InterruptedException(); // our root node this.compareResult = new DiffNode(Differencer.CONFLICTING); final RevWalk rw = new RevWalk(repo); // get the "right" side (MERGE_HEAD for merge, ORIG_HEAD for rebase) final RevCommit rightCommit; try { String target; if (repo.getRepositoryState().equals(RepositoryState.MERGING)) target = Constants.MERGE_HEAD; else if (repo.getRepositoryState().equals(RepositoryState.REBASING_INTERACTIVE)) target = readFile(repo.getDirectory(), RebaseCommand.REBASE_MERGE + File.separatorChar + RebaseCommand.STOPPED_SHA); else target = Constants.ORIG_HEAD; ObjectId mergeHead = repo.resolve(target); if (mergeHead == null) throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, target)); rightCommit = rw.parseCommit(mergeHead); } catch (IOException e) { throw new InvocationTargetException(e); } // we need the HEAD, also to determine the common // ancestor final RevCommit headCommit; try { ObjectId head = repo.resolve(Constants.HEAD); if (head == null) throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, Constants.HEAD)); headCommit = rw.parseCommit(head); } catch (IOException e) { throw new InvocationTargetException(e); } final String fullBranch; try { fullBranch = repo.getFullBranch(); } catch (IOException e) { throw new InvocationTargetException(e); } // try to obtain the common ancestor List<RevCommit> startPoints = new ArrayList<RevCommit>(); rw.setRevFilter(RevFilter.MERGE_BASE); startPoints.add(rightCommit); startPoints.add(headCommit); RevCommit ancestorCommit; try { rw.markStart(startPoints); ancestorCommit = rw.next(); } catch (Exception e) { ancestorCommit = null; } if (monitor.isCanceled()) throw new InterruptedException(); // set the labels CompareConfiguration config = getCompareConfiguration(); config.setRightLabel(NLS.bind(LABELPATTERN, rightCommit.getShortMessage(), rightCommit.name())); if (!useWorkspace) config.setLeftLabel(NLS.bind(LABELPATTERN, headCommit.getShortMessage(), headCommit.name())); else config.setLeftLabel(UIText.GitMergeEditorInput_WorkspaceHeader); if (ancestorCommit != null) config.setAncestorLabel( NLS.bind(LABELPATTERN, ancestorCommit.getShortMessage(), ancestorCommit.name())); // set title and icon setTitle(NLS.bind(UIText.GitMergeEditorInput_MergeEditorTitle, new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repo), rightCommit.getShortMessage(), fullBranch })); // now we calculate the nodes containing the compare information try { for (IFile file : files) { if (monitor.isCanceled()) throw new InterruptedException(); monitor.setTaskName(file.getFullPath().toString()); RepositoryMapping map = RepositoryMapping.getMapping(file); String gitPath = map.getRepoRelativePath(file); if (gitPath == null) continue; // ignore everything in .git if (gitPath.startsWith(Constants.DOT_GIT)) continue; fileToDiffNode(file, gitPath, map, this.compareResult, rightCommit, headCommit, ancestorCommit, rw, monitor); } } catch (IOException e) { throw new InvocationTargetException(e); } return compareResult; }
From source file:org.eclipse.egit.ui.internal.repository.DropAdapterAssistant.java
License:Open Source License
@Override public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) { String[] data = (String[]) aDropTargetEvent.data; for (String folder : data) { File repoFile = new File(folder); if (FileKey.isGitRepository(repoFile, FS.DETECTED)) Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repoFile); // also a direct parent of a .git dir is allowed else if (!repoFile.getName().equals(Constants.DOT_GIT)) { File dotgitfile = new File(repoFile, Constants.DOT_GIT); if (FileKey.isGitRepository(dotgitfile, FS.DETECTED)) Activator.getDefault().getRepositoryUtil().addConfiguredRepository(dotgitfile); }/*from www. j ava2s . c om*/ } // the returned Status is not consumed anyway return Status.OK_STATUS; }
From source file:org.eclipse.egit.ui.internal.repository.DropAdapterAssistant.java
License:Open Source License
@Override public IStatus validateDrop(Object target, int operation, TransferData transferData) { // check that all paths are valid repository paths String[] folders = (String[]) FileTransfer.getInstance().nativeToJava(transferData); for (String folder : folders) { File repoFile = new File(folder); if (FileKey.isGitRepository(repoFile, FS.DETECTED)) { continue; }// www . ja v a 2s. co m // convenience: also allow the direct parent of .git if (!repoFile.getName().equals(Constants.DOT_GIT)) { File dotgitfile = new File(repoFile, Constants.DOT_GIT); if (FileKey.isGitRepository(dotgitfile, FS.DETECTED)) continue; } return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:org.eclipse.egit.ui.internal.repository.NewRepositoryWizard.java
License:Open Source License
@Override public boolean performFinish() { RepositoryCache cache = Activator.getDefault().getRepositoryCache(); try {//w w w . j ava2 s . c o m File repoFile = new File(myCreatePage.getDirectory()); if (!myCreatePage.getBare()) repoFile = new File(repoFile, Constants.DOT_GIT); Repository newRepo = cache.lookupRepository(repoFile); newRepo.create(myCreatePage.getBare()); Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repoFile); } catch (IOException e) { org.eclipse.egit.ui.Activator.handleError(e.getMessage(), e, false); } return true; }
From source file:org.eclipse.egit.ui.internal.sharing.ExistingOrNewPage.java
License:Open Source License
public void createControl(Composite parent) { Group g = new Group(parent, SWT.NONE); g.setLayout(new GridLayout(3, false)); g.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); tree = new Tree(g, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK); viewer = new CheckboxTreeViewer(tree); tree.setHeaderVisible(true);// w w w . j av a2 s. c om tree.setLayout(new GridLayout()); tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(3, 1).create()); viewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { if (event.getChecked()) { ProjectAndRepo checkable = (ProjectAndRepo) event.getElement(); for (TreeItem ti : tree.getItems()) { if (ti.getItemCount() > 0 || ((ProjectAndRepo) ti.getData()).getRepo().equals("")) //$NON-NLS-1$ ti.setChecked(false); for (TreeItem subTi : ti.getItems()) { IProject project = ((ProjectAndRepo) subTi.getData()).getProject(); if (checkable.getProject() != null && !subTi.getData().equals(checkable) && checkable.getProject().equals(project)) subTi.setChecked(false); } } } } }); TreeColumn c1 = new TreeColumn(tree, SWT.NONE); c1.setText(UIText.ExistingOrNewPage_HeaderProject); c1.setWidth(100); TreeColumn c2 = new TreeColumn(tree, SWT.NONE); c2.setText(UIText.ExistingOrNewPage_HeaderPath); c2.setWidth(400); TreeColumn c3 = new TreeColumn(tree, SWT.NONE); c3.setText(UIText.ExistingOrNewPage_HeaderRepository); c3.setWidth(200); for (IProject project : myWizard.projects) { RepositoryFinder repositoryFinder = new RepositoryFinder(project); try { Collection<RepositoryMapping> mappings; mappings = repositoryFinder.find(new NullProgressMonitor()); Iterator<RepositoryMapping> mi = mappings.iterator(); RepositoryMapping m = mi.hasNext() ? mi.next() : null; if (m == null) { // no mapping found, enable repository creation TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText(0, project.getName()); treeItem.setText(1, project.getLocation().toOSString()); treeItem.setText(2, ""); //$NON-NLS-1$ treeItem.setData(new ProjectAndRepo(project, "")); //$NON-NLS-1$ } else if (!mi.hasNext()) { // exactly one mapping found TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText(0, project.getName()); treeItem.setText(1, project.getLocation().toOSString()); fillTreeItemWithGitDirectory(m, treeItem, false); treeItem.setData(new ProjectAndRepo(project, treeItem.getText(2))); treeItem.setChecked(true); } else { TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText(0, project.getName()); treeItem.setText(1, project.getLocation().toOSString()); treeItem.setData(new ProjectAndRepo(null, null)); TreeItem treeItem2 = new TreeItem(treeItem, SWT.NONE); treeItem2.setText(0, project.getName()); fillTreeItemWithGitDirectory(m, treeItem2, true); treeItem2.setData(new ProjectAndRepo(project, treeItem2.getText(2))); while (mi.hasNext()) { // fill in additional mappings m = mi.next(); treeItem2 = new TreeItem(treeItem, SWT.NONE); treeItem2.setText(0, project.getName()); fillTreeItemWithGitDirectory(m, treeItem2, true); treeItem2.setData(new ProjectAndRepo(m.getContainer().getProject(), treeItem2.getText(2))); } treeItem.setExpanded(true); } } catch (CoreException e) { TreeItem treeItem2 = new TreeItem(tree, SWT.BOLD | SWT.ITALIC); treeItem2.setText(e.getMessage()); } } button = new Button(g, SWT.PUSH); button.setLayoutData(GridDataFactory.fillDefaults().create()); button.setText(UIText.ExistingOrNewPage_CreateButton); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { File gitDir = new File(repositoryToCreate.getText(), Constants.DOT_GIT); try { Repository repository = new FileRepository(gitDir); repository.create(); for (IProject project : getProjects().keySet()) { // If we don't refresh the project directories right // now we won't later know that a .git directory // exists within it and we won't mark the .git // directory as a team-private member. Failure // to do so might allow someone to delete // the .git directory without us stopping them. // (Half lie, we should optimize so we do not // refresh when the .git is not within the project) // if (!gitDir.toString().contains("..")) //$NON-NLS-1$ project.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor()); } RepositoryUtil util = Activator.getDefault().getRepositoryUtil(); util.addConfiguredRepository(gitDir); } catch (IOException e1) { String msg = NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToCreateRepository, gitDir.toString()); org.eclipse.egit.ui.Activator.handleError(msg, e1, true); } catch (CoreException e2) { String msg = NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToRefreshRepository, gitDir); org.eclipse.egit.ui.Activator.handleError(msg, e2, true); } for (TreeItem ti : tree.getSelection()) { ti.setText(2, gitDir.toString()); ((ProjectAndRepo) ti.getData()).repo = gitDir.toString(); ti.setChecked(true); } updateCreateOptions(); getContainer().updateButtons(); } }); repositoryToCreate = new Text(g, SWT.SINGLE | SWT.BORDER); repositoryToCreate.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(1, 1).create()); repositoryToCreate.addListener(SWT.Modify, new Listener() { public void handleEvent(Event e) { if (repositoryToCreate.getText().equals("")) { //$NON-NLS-1$ button.setEnabled(false); return; } IPath fromOSString = Path.fromOSString(repositoryToCreate.getText()); button.setEnabled(minumumPath.matchingFirstSegments(fromOSString) == fromOSString.segmentCount()); } }); dotGitSegment = new Text(g, SWT.NONE); dotGitSegment.setEnabled(false); dotGitSegment.setEditable(false); dotGitSegment.setText(File.separatorChar + Constants.DOT_GIT); dotGitSegment.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create()); tree.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateCreateOptions(); } }); updateCreateOptions(); Dialog.applyDialogFont(g); setControl(g); }
From source file:org.eclipse.egit.ui.test.nonswt.decoration.DecoratableResourceHelperTest.java
License:Open Source License
@Before public void setUp() throws Exception { super.setUp(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); gitDir = new File(root.getLocation().toFile(), Constants.DOT_GIT); repository = new FileRepository(gitDir); repository.create();/*from w w w. j ava2 s . co m*/ repository.close(); repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir); project = root.getProject(TEST_PROJECT); project.create(null); project.open(null); project.getFolder(TEST_FOLDER2).create(true, true, null); IFile testFile2 = project.getFile(TEST_FILE2); testFile2.create(new ByteArrayInputStream("content".getBytes()), true, null); RepositoryMapping mapping = new RepositoryMapping(project, gitDir); GitProjectData projectData = new GitProjectData(project); projectData.setRepositoryMappings(Collections.singleton(mapping)); projectData.store(); GitProjectData.add(project, projectData); RepositoryProvider.map(project, GitProvider.class.getName()); git = new Git(repository); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); indexDiffCacheEntry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository); waitForIndexDiffUpdate(false); }
From source file:org.eclipse.egit.ui.variables.DynamicVariablesTest.java
License:Open Source License
@Before public void setUp() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); FileUtils.mkdir(new File(root.getLocation().toFile(), "Sub"), true); gitDir = new File(new File(root.getLocation().toFile(), "Sub"), Constants.DOT_GIT); repository = new FileRepository(gitDir); repository.create();/*w w w .j av a2 s.co m*/ project = root.getProject(TEST_PROJECT); project.create(null); project.open(null); IProjectDescription description = project.getDescription(); description.setLocation(root.getLocation().append(TEST_PROJECT_LOC)); project.move(description, IResource.FORCE, null); project2 = root.getProject(TEST_PROJECT2); project2.create(null); project2.open(null); gitDir2 = new File(project2.getLocation().toFile().getAbsoluteFile(), Constants.DOT_GIT); repository2 = new FileRepository(gitDir2); repository2.create(); RepositoryMapping mapping = new RepositoryMapping(project, gitDir); RepositoryMapping mapping2 = new RepositoryMapping(project2, gitDir2); GitProjectData projectData = new GitProjectData(project); GitProjectData projectData2 = new GitProjectData(project2); projectData.setRepositoryMappings(Collections.singletonList(mapping)); projectData.store(); projectData2.setRepositoryMappings(Collections.singletonList(mapping2)); projectData2.store(); GitProjectData.add(project, projectData); GitProjectData.add(project2, projectData2); RepositoryProvider.map(project, GitProvider.class.getName()); RepositoryProvider.map(project2, GitProvider.class.getName()); FileWriter fileWriter = new FileWriter(new File(repository.getWorkTree(), TEST_PROJECT + "/" + TEST_FILE)); fileWriter.write("Some data"); fileWriter.close(); FileWriter fileWriter2 = new FileWriter(new File(repository2.getWorkTree(), TEST_FILE2)); fileWriter2.write("Some other data"); fileWriter2.close(); project.refreshLocal(IResource.DEPTH_INFINITE, null); project2.refreshLocal(IResource.DEPTH_INFINITE, null); git = new Git(repository); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); git = new Git(repository2); git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); git.branchRename().setNewName("main").call(); }