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:com.google.devtools.build.lib.bazel.repository.GitCloneFunction.java

License:Open Source License

private boolean isUpToDate(GitRepositoryDescriptor descriptor) {
    // Initializing/checking status of/etc submodules cleanly is hard, so don't try for now.
    if (descriptor.initSubmodules) {
        return false;
    }/*  w  ww.  j  a v  a  2s . c o  m*/
    Repository repository = null;
    try {
        repository = new FileRepositoryBuilder()
                .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true)
                .build();
        ObjectId head = repository.resolve(Constants.HEAD);
        ObjectId checkout = repository.resolve(descriptor.checkout);
        if (head != null && checkout != null && head.equals(checkout)) {
            Status status = Git.wrap(repository).status().call();
            if (!status.hasUncommittedChanges()) {
                // new_git_repository puts (only) BUILD and WORKSPACE, and
                // git_repository doesn't add any files.
                Set<String> untracked = status.getUntracked();
                if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD")
                        && untracked.contains("WORKSPACE"))) {
                    return true;
                }
            }
        }
    } catch (GitAPIException | IOException e) {
        // Any exceptions here, we'll just blow it away and try cloning fresh.
        // The fresh clone avoids any weirdness due to what's there and has nicer
        // error reporting.
    } finally {
        if (repository != null) {
            repository.close();
        }
    }
    return false;
}

From source file:com.google.devtools.build.lib.bazel.repository.GitCloner.java

License:Open Source License

private static boolean isUpToDate(GitRepositoryDescriptor descriptor) {
    // Initializing/checking status of/etc submodules cleanly is hard, so don't try for now.
    if (descriptor.initSubmodules) {
        return false;
    }//from  w w w.j  a v  a2  s .  co m
    Repository repository = null;
    try {
        repository = new FileRepositoryBuilder()
                .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true)
                .build();
        ObjectId head = repository.resolve(Constants.HEAD);
        ObjectId checkout = repository.resolve(descriptor.checkout);
        if (head != null && checkout != null && head.equals(checkout)) {
            Status status = Git.wrap(repository).status().call();
            if (!status.hasUncommittedChanges()) {
                // new_git_repository puts (only) BUILD and WORKSPACE, and
                // git_repository doesn't add any files.
                Set<String> untracked = status.getUntracked();
                if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD")
                        && untracked.contains("WORKSPACE"))) {
                    return true;
                }
            }
        }
    } catch (GitAPIException | IOException e) {
        // Any exceptions here, we'll just blow it away and try cloning fresh.
        // The fresh clone avoids any weirdness due to what's there and has nicer
        // error reporting.
    } finally {
        if (repository != null) {
            repository.close();
        }
    }
    return false;
}

From source file:com.google.gerrit.server.git.LocalDiskRepositoryManager.java

License:Apache License

private Repository openRepository(Path path, Project.NameKey name) throws RepositoryNotFoundException {
    if (isUnreasonableName(name)) {
        throw new RepositoryNotFoundException("Invalid name: " + name);
    }/*from   www. j  a  v  a  2 s  .c o m*/
    File gitDir = path.resolve(name.get()).toFile();
    if (!names.contains(name)) {
        // The this.names list does not hold the project-name but it can still exist
        // on disk; for instance when the project has been created directly on the
        // file-system through replication.
        //
        if (!name.get().endsWith(Constants.DOT_GIT_EXT)) {
            if (FileKey.resolve(gitDir, FS.DETECTED) != null) {
                onCreateProject(name);
            } else {
                throw new RepositoryNotFoundException(gitDir);
            }
        } else {
            final File directory = gitDir;
            if (FileKey.isGitRepository(new File(directory, Constants.DOT_GIT), FS.DETECTED)) {
                onCreateProject(name);
            } else if (FileKey.isGitRepository(
                    new File(directory.getParentFile(), directory.getName() + Constants.DOT_GIT_EXT),
                    FS.DETECTED)) {
                onCreateProject(name);
            } else {
                throw new RepositoryNotFoundException(gitDir);
            }
        }
    }
    final FileKey loc = FileKey.lenient(gitDir, FS.DETECTED);
    try {
        return RepositoryCache.open(loc);
    } catch (IOException e1) {
        final RepositoryNotFoundException e2;
        e2 = new RepositoryNotFoundException("Cannot open repository " + name);
        e2.initCause(e1);
        throw e2;
    }
}

From source file:com.microsoft.tfs.client.common.ui.teambuild.egit.repositories.GitRepositoriesMap.java

License:Open Source License

private List<Repository> findRegisteredRepositories() {
    final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    final List<String> repositoryFolders = util.getConfiguredRepositories();

    final List<Repository> repositories = new ArrayList<Repository>();

    for (final String repositoryFolder : repositoryFolders) {
        final File folder = new File(repositoryFolder);
        if (!folder.exists() || !folder.isDirectory()) {
            continue;
        }//from   ww  w  . jav  a 2s  . c  o  m

        if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
            continue;
        }

        final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);

        try {
            repositories.add(rb.build());
        } catch (final Exception e) {
            log.error("Error loading Git repository " + repositoryFolder, e); //$NON-NLS-1$
            continue;
        }
    }

    return repositories;
}

From source file:com.microsoft.tfs.client.eclipse.ui.egit.importwizard.FindEclipseProjectsCommand.java

License:Open Source License

@Override
protected IStatus doRun(final IProgressMonitor progressMonitor) throws Exception {
    try {/*from w w w.  j  av  a 2s  .c om*/
        for (int i = 0; i < folders.size(); i++) {
            if (progressMonitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }

            final File folder = folders.get(i);
            progressMonitor.subTask(folder.getPath());

            if (folder.getName().equals(Constants.DOT_GIT) && FileKey.isGitRepository(folder, FS.DETECTED)) {
                continue;
            }

            final String canonicalFolderPath = folder.getCanonicalPath();
            if (visitedFolders.contains(canonicalFolderPath)) {
                continue;
            } else {
                visitedFolders.add(canonicalFolderPath);
            }

            progressMonitor.subTask(MessageFormat.format(subTaskNameFormat, folder.getName()));

            final File[] files = folder.listFiles();
            if (files == null || files.length == 0) {
                continue;
            }

            /*
             * Let's check first files for a project description file.
             */
            boolean found = false;

            for (final File file : files) {
                if (fileFilter.accept(file)) {
                    projects.add(new EclipseProjectInfo(file, workspace));
                    found = true;
                    break;
                }
            }

            /*
             * If we've found one, we skip the nested folders unless deep
             * search has been requested.
             */
            if (found && !searchNested) {
                continue;
            }

            /*
             * We haven't found a project description file among the direct
             * children of the folder or nested projects search has been
             * requested. Let's look into nested sub-folders.
             */
            for (final File file : files) {
                if (folderFilter.accept(file) && !visitedFolders.contains(file.getCanonicalPath())) {
                    folders.add(file);
                }
            }
        }
    } catch (final IOException e) {
        return new Status(IStatus.ERROR, TFSCommonClientPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);
    }

    return Status.OK_STATUS;
}

From source file:com.microsoft.tfs.client.eclipse.ui.egit.teamexplorer.TeamExplorerGitRepositoriesSection.java

License:Open Source License

private void loadRegisteredRepositories() {
    repositoryMap = new TreeMap<String, Repository>();
    final List<String> repositoryFolders = Activator.getDefault().getRepositoryUtil()
            .getConfiguredRepositories();

    for (final String repositoryFolder : repositoryFolders) {
        final File folder = new File(repositoryFolder);
        if (!folder.exists() || !folder.isDirectory()) {
            continue;
        }/* w  w w . j  a  va 2s . c  o m*/

        if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
            continue;
        }

        final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);

        try {
            final Repository repo = rb.build();
            final StoredConfig repositoryConfig = repo.getConfig();
            final Set<String> remotes = repositoryConfig.getSubsections(REMOTES_SECTION_NAME);

            for (final String remoteName : remotes) {
                final String remoteURL = repositoryConfig.getString(REMOTES_SECTION_NAME, remoteName,
                        URL_VALUE_NAME);
                repositoryMap.put(remoteURL, repo);
            }
        } catch (final Exception e) {
            log.error("Error loading local Git repository " + repositoryFolder, e); //$NON-NLS-1$
            continue;
        }
    }
}

From source file:com.peergreen.configuration.git.GitConfiguration.java

License:Apache License

@Override
public ConfigRepository getRepository(String name) throws RepositoryException {
    check();//from   w w  w  .  j a  v a 2s . c  o m

    // Sets the git directory from the given repository name
    File repositoryDir = new File(rootDirectory, name);
    File gitDir = new File(repositoryDir, Constants.DOT_GIT);

    // Find the git directory
    FileRepository fileRepository = null;
    try {
        fileRepository = new FileRepositoryBuilder() //
                .setGitDir(gitDir) // --git-dir if supplied, no-op if null
                .readEnvironment() // scan environment GIT_* variables
                .findGitDir().build();
    } catch (IOException e) {
        throw new RepositoryException("Unable to find a repository for the path '" + name + "'.", e);
    }

    // do not exist yet on the filesystem, create all the directories
    if (!gitDir.exists()) {
        try {
            fileRepository.create();
        } catch (IOException e) {
            throw new RepositoryException("Cannot create repository", e);
        }

        // Create the first commit in order to initiate the repository.
        Git git = new Git(fileRepository);
        CommitCommand commit = git.commit();
        try {
            commit.setMessage("Initial setup for the git configuration of '" + name + "'").call();
        } catch (GitAPIException e) {
            throw new RepositoryException("Cannot init the git repository '" + name + "'", e);
        }

    }

    return new GitRepository(fileRepository);

}

From source file:com.pieceof8.gradle.snapshot.GitScmProvider.java

License:Apache License

/**
 * Constructs an {@code ScmProvider} for the Git SCM tool.
 *
 * @param project The (Gradle) project this plugin is being applied to.
 * @see org.gradle.api.Project/* w  w w .j  a  v a  2s.co m*/
 */
public GitScmProvider(final @NonNull Project project) {
    super(project, Constants.DOT_GIT);

    this.project = project;
    this.extension = project.getExtensions().getByType(SnapshotPluginExtension.class);
}

From source file:data.models.DataGit.java

License:Open Source License

public DataGit(String zippedRepoLocation, String repoName, String rootProjectName, String modelName) {
    try {//from w  ww  .  j  a v  a 2  s . co m
        this.disposers = new ArrayList<Runnable>();
        String systemTmpDir = System.getProperty("java.io.tmpdir");
        Bundle bundle = Platform.getBundle("org.eclipse.emf.compare.tests.performance");
        URL entry = bundle.getEntry(zippedRepoLocation);
        repoFile = new File(systemTmpDir + File.separator + repoName);

        // Delete repo if it already exists
        GitUtil.deleteRepo(repoFile);

        // Unzip repository to temp directory
        GitUtil.unzipRepo(entry, systemTmpDir, new NullProgressMonitor());

        Job importJob = new Job("ImportProjects") {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                GitUtil.importProjectsFromRepo(repoFile);
                return Status.OK_STATUS;
            }
        };
        importJob.schedule();
        importJob.join();

        Job connectJob = new Job("ConnectProjects") {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    // Connect eclipse projects to egit repository
                    File gitDir = new File(repoFile, Constants.DOT_GIT);
                    repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir);
                    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                    GitUtil.connectProjectsToRepo(repository, Arrays.asList(projects));
                } catch (IOException e) {
                    Throwables.propagate(e);
                }
                return Status.OK_STATUS;
            }
        };
        connectJob.schedule();
        connectJob.join();

        IProject rootProject = ResourcesPlugin.getWorkspace().getRoot().getProject(rootProjectName);

        final IFile model = rootProject.getFile(new Path(modelName));
        final String fullPath = model.getFullPath().toString();
        final Subscriber subscriber = GitUtil.createSubscriberForComparison(repository, MASTER, MODIFIED, model,
                disposers);
        final IStorageProviderAccessor accessor = new SubscriberStorageAccessor(subscriber);
        final IStorageProvider sourceProvider = accessor.getStorageProvider(model,
                IStorageProviderAccessor.DiffSide.SOURCE);
        final IStorageProvider remoteProvider = accessor.getStorageProvider(model,
                IStorageProviderAccessor.DiffSide.REMOTE);
        final IStorageProvider ancestorProvider = accessor.getStorageProvider(model,
                IStorageProviderAccessor.DiffSide.ORIGIN);
        assertNotNull(sourceProvider);
        assertNotNull(remoteProvider);
        assertNotNull(ancestorProvider);

        final IProgressMonitor m = new NullProgressMonitor();
        final IStorageProviderAccessor storageAccessor = new SubscriberStorageAccessor(subscriber);
        final ITypedElement left = new StorageTypedElement(sourceProvider.getStorage(m), fullPath);
        final ITypedElement right = new StorageTypedElement(remoteProvider.getStorage(m), fullPath);
        final ITypedElement origin = new StorageTypedElement(ancestorProvider.getStorage(m), fullPath);
        ModelResolverRegistry mrr = EMFCompareIDEUIPlugin.getDefault().getModelResolverRegistry();
        IModelResolver resolver = mrr.getBestResolverFor(sourceProvider.getStorage(m));
        final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(resolver,
                new IdenticalResourceMinimizer(), storageAccessor);
        scope = scopeBuilder.build(left, right, origin, m);

        resourceSets.add((ResourceSet) scope.getLeft());
        resourceSets.add((ResourceSet) scope.getRight());
        resourceSets.add((ResourceSet) scope.getOrigin());

    } catch (IOException e) {
        Throwables.propagate(e);
    } catch (CoreException e) {
        Throwables.propagate(e);
    } catch (InterruptedException e) {
        Throwables.propagate(e);
    }
}

From source file:de.hub.srcrepo.ProjectUtil.java

License:Open Source License

public static boolean findProjectFiles(final Collection<File> files, final File directory,
        final Set<String> visistedDirs, final IProgressMonitor monitor) {
    if (directory == null)
        return false;

    if (directory.getName().equals(Constants.DOT_GIT) && FileKey.isGitRepository(directory, FS.DETECTED))
        return false;

    IProgressMonitor pm = monitor;//  w w w  .  ja  v  a  2s.  co  m
    if (pm == null)
        pm = new NullProgressMonitor();
    else if (pm.isCanceled())
        return false;

    pm.subTask(NLS.bind(CoreText.ProjectUtil_taskCheckingDirectory, directory.getPath()));

    final File[] contents = directory.listFiles();
    if (contents == null || contents.length == 0)
        return false;

    Set<String> directoriesVisited;
    // Initialize recursion guard for recursive symbolic links
    if (visistedDirs == null) {
        directoriesVisited = new HashSet<String>();
        try {
            directoriesVisited.add(directory.getCanonicalPath());
        } catch (IOException exception) {
            Activator.logError(exception.getLocalizedMessage(), exception);
        }
    } else
        directoriesVisited = visistedDirs;

    // first look for project description files
    final String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME;
    for (int i = 0; i < contents.length; i++) {
        File file = contents[i];
        if (file.isFile() && file.getName().equals(dotProject)) {
            files.add(file);
            // don't search sub-directories since we can't have nested
            // projects
            return true;
        }
    }
    // no project description found, so recurse into sub-directories
    for (int i = 0; i < contents.length; i++) {
        // Skip non-directories
        if (!contents[i].isDirectory())
            continue;
        // Skip .metadata folders
        if (contents[i].getName().equals(METADATA_FOLDER))
            continue;
        try {
            String canonicalPath = contents[i].getCanonicalPath();
            if (!directoriesVisited.add(canonicalPath)) {
                // already been here --> do not recurse
                continue;
            }
        } catch (IOException exception) {
            Activator.logError(exception.getLocalizedMessage(), exception);

        }
        findProjectFiles(files, contents[i], directoriesVisited, pm);
    }
    return true;
}