Example usage for org.eclipse.jgit.lib Constants DOT_GIT

List of usage examples for org.eclipse.jgit.lib Constants DOT_GIT

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants DOT_GIT.

Prototype

String DOT_GIT

To view the source code for org.eclipse.jgit.lib Constants DOT_GIT.

Click Source Link

Document

Default name for the Git repository directory

Usage

From source file:org.eclipse.egit.core.op.ConnectProviderOperation.java

License:Open Source License

/**
 * Create a new connection operation to execute within the workspace.
 * <p>/*w w  w.  j ava 2 s .  c o  m*/
 * Uses <code>.git</code> as a default relative path to repository.
 * @see #ConnectProviderOperation(IProject, File)
 *
 * @param proj
 *            the project to connect to the Git team provider.
 */
public ConnectProviderOperation(final IProject proj) {
    this(proj, proj.getLocation().append(Constants.DOT_GIT).toFile());
}

From source file:org.eclipse.egit.core.project.GitProjectData.java

License:Open Source License

/**
 * Hide our private parts from the navigators other browsers.
 *
 * @throws CoreException/*from   w ww  .j  a  v a  2s.  c  om*/
 */
public void markTeamPrivateResources() throws CoreException {
    for (final Object rmObj : mappings) {
        final RepositoryMapping rm = (RepositoryMapping) rmObj;
        final IContainer c = rm.getContainer();
        if (c == null)
            continue; // Not fully mapped yet?

        final IResource dotGit = c.findMember(Constants.DOT_GIT);
        if (dotGit != null) {
            try {
                final Repository r = rm.getRepository();
                final File dotGitDir = dotGit.getLocation().toFile().getCanonicalFile();
                if (dotGitDir.equals(r.getDirectory())) {
                    trace("teamPrivate " + dotGit); //$NON-NLS-1$
                    dotGit.setTeamPrivateMember(true);
                }
            } catch (IOException err) {
                throw new CoreException(Activator.error(CoreText.Error_CanonicalFile, err));
            }
        }
    }
}

From source file:org.eclipse.egit.core.project.GitProjectData.java

License:Open Source License

private void map(final RepositoryMapping m) {
    final IResource r;
    final File git;
    final IResource dotGit;
    IContainer c = null;//from w  w w  . j  av a2s  .  c om

    m.clear();
    r = getProject().findMember(m.getContainerPath());
    if (r instanceof IContainer) {
        c = (IContainer) r;
    } else {
        c = (IContainer) r.getAdapter(IContainer.class);
    }

    if (c == null) {
        Activator.logError(CoreText.GitProjectData_mappedResourceGone,
                new FileNotFoundException(m.getContainerPath().toString()));
        m.clear();
        return;
    }
    m.setContainer(c);

    git = c.getLocation().append(m.getGitDirPath()).toFile();
    if (!git.isDirectory() || !new File(git, "config").isFile()) { //$NON-NLS-1$
        Activator.logError(CoreText.GitProjectData_mappedResourceGone,
                new FileNotFoundException(m.getContainerPath().toString()));
        m.clear();
        return;
    }

    try {
        m.setRepository(Activator.getDefault().getRepositoryCache().lookupRepository(git));
    } catch (IOException ioe) {
        Activator.logError(CoreText.GitProjectData_mappedResourceGone,
                new FileNotFoundException(m.getContainerPath().toString()));
        m.clear();
        return;
    }

    m.fireRepositoryChanged();

    trace("map " //$NON-NLS-1$
            + c + " -> " //$NON-NLS-1$
            + m.getRepository());
    try {
        c.setSessionProperty(MAPPING_KEY, m);
    } catch (CoreException err) {
        Activator.logError(CoreText.GitProjectData_failedToCacheRepoMapping, err);
    }

    dotGit = c.findMember(Constants.DOT_GIT);
    if (dotGit != null && dotGit.getLocation().toFile().equals(git)) {
        protect(dotGit);
    }
}

From source file:org.eclipse.egit.core.project.RepositoryFinder.java

License:Open Source License

private void find(final IProgressMonitor m, final IContainer c) throws CoreException {
    final IPath loc = c.getLocation();

    m.beginTask("", 101); //$NON-NLS-1$
    m.subTask(CoreText.RepositoryFinder_finding);
    try {// w  ww  .  j a v a 2s . c  o m
        if (loc != null) {
            final File fsLoc = loc.toFile();
            assert fsLoc.isAbsolute();
            final File ownCfg = configFor(fsLoc);
            final IResource[] children;

            if (ownCfg.isFile()) {
                register(c, ownCfg.getParentFile());
            }
            if (c.isLinked() || c instanceof IProject) {
                File p = fsLoc.getParentFile();
                while (p != null) {
                    // TODO is this the right location?
                    if (GitTraceLocation.CORE.isActive())
                        GitTraceLocation.getTrace().trace(GitTraceLocation.CORE.getLocation(),
                                "Looking at candidate dir: " //$NON-NLS-1$
                                        + p);
                    final File pCfg = configFor(p);
                    if (pCfg.isFile()) {
                        register(c, pCfg.getParentFile());
                    }
                    if (ceilingDirectories.contains(p.getPath()))
                        break;
                    p = p.getParentFile();
                }
            }
            m.worked(1);

            children = c.members();
            if (children != null && children.length > 0) {
                final int scale = 100 / children.length;
                for (int k = 0; k < children.length; k++) {
                    final IResource o = children[k];
                    if (o instanceof IContainer && !o.getName().equals(Constants.DOT_GIT)) {
                        find(new SubProgressMonitor(m, scale), (IContainer) o);
                    } else {
                        m.worked(scale);
                    }
                }
            }
        }
    } finally {
        m.done();
    }
}

From source file:org.eclipse.egit.core.project.RepositoryFinder.java

License:Open Source License

private File configFor(final File fsLoc) {
    return new File(new File(fsLoc, Constants.DOT_GIT), "config"); //$NON-NLS-1$
}

From source file:org.eclipse.egit.core.storage.GitBlobStorageTest.java

License:Open Source License

@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
    IProgressMonitor progress = new NullProgressMonitor();
    TestProject singleRepoProject = new TestProject(true, "Project-2");
    IProject proj = singleRepoProject.getProject();
    File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
    if (singleProjectGitDir.exists())
        FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);

    Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
    singleProjectRepo.create();/*from w  w w  .ja  v a2 s .c  o m*/

    // Repository must be mapped in order to test the GitFileHistory
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
    ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
    connectOp.execute(progress);

    try {
        IFile file = proj.getFile("file");
        file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
        Git git = new Git(singleProjectRepo);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true)
                .setMessage("First commit").call();

        GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
        IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
        assertNotNull(fh);
        assertEquals(fh.getFileRevisions().length, 1);
        assertNotNull(fh.getFileRevision(commit.getId().getName()));
    } finally {
        DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(
                Collections.singletonList(proj));
        disconnectOp.execute(progress);
        Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
        singleProjectRepo.close();
        singleRepoProject.dispose();
    }
}

From source file:org.eclipse.egit.core.test.CommitUtilTest.java

License:Open Source License

@Override
@Before/*ww  w .  ja va 2  s. co m*/
public void setUp() throws Exception {
    super.setUp();
    gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
    testRepository = new TestRepository(gitDir);
    testRepository.connect(project.getProject());
    testRepository.createInitialCommit("initial");

    File file = testRepository.createFile(project.getProject(), "file-1");
    commit1 = testRepository.addAndCommit(project.getProject(), file, "commit 1");
    testRepository.appendFileContent(file, "file-2");
    commit2 = testRepository.addAndCommit(project.getProject(), file, "commit 2");
    testRepository.appendFileContent(file, "file-3");
    commit3 = testRepository.addAndCommit(project.getProject(), file, "commit 3");
}

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 w w  w  . j  a v a  2s .c  o  m*/
    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.GitTestCase.java

License:Open Source License

@Before
public void setUp() throws Exception {
    // ensure there are no shared Repository instances left
    // when starting a new test
    Activator.getDefault().getRepositoryCache().clear();
    MockSystemReader mockSystemReader = new MockSystemReader();
    SystemReader.setInstance(mockSystemReader);
    mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY,
            ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsoluteFile().toString());
    project = new TestProject(true);
    gitDir = new File(project.getProject().getWorkspace().getRoot().getRawLocation().toFile(),
            Constants.DOT_GIT);
    if (gitDir.exists())
        FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
}

From source file:org.eclipse.egit.core.test.internal.mapping.T0002_HistoryTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    super.setUp();

    project.createSourceFolder();//from   ww w  .  java  2s . co  m
    gitDir = new File(project.getProject().getWorkspace().getRoot().getRawLocation().toFile(),
            Constants.DOT_GIT);
    thisGit = new Repository(gitDir);
    workDir = thisGit.getWorkDir();
    thisGit.create();
    objectWriter = new ObjectWriter(thisGit);

    tree = new Tree(thisGit);
    Tree projectTree = tree.addTree("Project-1");
    File project1_a_txt = createFile("Project-1/A.txt", "A.txt - first version\n");
    addFile(projectTree, project1_a_txt);
    projectTree.setId(objectWriter.writeTree(projectTree));
    File project1_b_txt = createFile("Project-1/B.txt", "B.txt - first version\n");
    addFile(projectTree, project1_b_txt);
    projectTree.setId(objectWriter.writeTree(projectTree));
    tree.setId(objectWriter.writeTree(tree));
    Commit commit = new Commit(thisGit);
    commit.setAuthor(new PersonIdent(jauthor, new Date(0L), TimeZone.getTimeZone("GMT+1")));
    commit.setCommitter(new PersonIdent(jcommitter, new Date(0L), TimeZone.getTimeZone("GMT+1")));
    commit.setMessage("Foo\n\nMessage");
    commit.setTree(tree);
    ObjectId commitId = objectWriter.writeCommit(commit);

    tree = new Tree(thisGit);
    projectTree = tree.addTree("Project-1");
    addFile(projectTree, project1_a_txt);

    File project1_b_v2_txt = createFile("Project-1/B.txt", "B.txt - second version\n");
    addFile(projectTree, project1_b_v2_txt);
    projectTree.setId(objectWriter.writeTree(projectTree));
    tree.setId(objectWriter.writeTree(tree));
    commit = new Commit(thisGit);
    commit.setAuthor(new PersonIdent(jauthor, new Date(0L), TimeZone.getTimeZone("GMT+1")));
    commit.setCommitter(new PersonIdent(jcommitter, new Date(0L), TimeZone.getTimeZone("GMT+1")));
    commit.setMessage("Modified");
    commit.setParentIds(new ObjectId[] { commitId });
    commit.setTree(tree);
    commitId = objectWriter.writeCommit(commit);

    RefUpdate lck = thisGit.updateRef("refs/heads/master");
    assertNotNull("obtained lock", lck);
    lck.setNewObjectId(commitId);
    assertEquals(RefUpdate.Result.NEW, lck.forceUpdate());

    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
    operation.execute(null);
}