Search in sources :

Example 1 with NoRemoteRepositoryException

use of org.eclipse.jgit.errors.NoRemoteRepositoryException in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepository method refresh.

/**
 * Get the working directory ready.
 */
public String refresh(String label) {
    Git git = null;
    try {
        git = createGitClient();
        if (shouldPull(git)) {
            FetchResult fetchStatus = fetch(git, label);
            if (deleteUntrackedBranches && fetchStatus != null) {
                deleteUntrackedLocalBranches(fetchStatus.getTrackingRefUpdates(), git);
            }
            // checkout after fetch so we can get any new branches, tags, ect.
            checkout(git, label);
            if (isBranch(git, label)) {
                // merge results from fetch
                merge(git, label);
                if (!isClean(git, label)) {
                    logger.warn("The local repository is dirty or ahead of origin. Resetting" + " it to origin/" + label + ".");
                    resetHard(git, label, LOCAL_BRANCH_REF_PREFIX + label);
                }
            }
        } else {
            // nothing to update so just checkout
            checkout(git, label);
        }
        // always return what is currently HEAD as the version
        return git.getRepository().findRef("HEAD").getObjectId().getName();
    } catch (RefNotFoundException e) {
        throw new NoSuchLabelException("No such label: " + label, e);
    } catch (NoRemoteRepositoryException e) {
        throw new NoSuchRepositoryException("No such repository: " + getUri(), e);
    } catch (GitAPIException e) {
        throw new NoSuchRepositoryException("Cannot clone or checkout repository: " + getUri(), e);
    } catch (Exception e) {
        throw new IllegalStateException("Cannot load environment", e);
    } finally {
        try {
            if (git != null) {
                git.close();
            }
        } catch (Exception e) {
            this.logger.warn("Could not close git repository", e);
        }
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) FetchResult(org.eclipse.jgit.transport.FetchResult) RefNotFoundException(org.eclipse.jgit.api.errors.RefNotFoundException) NoRemoteRepositoryException(org.eclipse.jgit.errors.NoRemoteRepositoryException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoRemoteRepositoryException(org.eclipse.jgit.errors.NoRemoteRepositoryException) IOException(java.io.IOException) RefNotFoundException(org.eclipse.jgit.api.errors.RefNotFoundException)

Aggregations

IOException (java.io.IOException)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RefNotFoundException (org.eclipse.jgit.api.errors.RefNotFoundException)1 NoRemoteRepositoryException (org.eclipse.jgit.errors.NoRemoteRepositoryException)1 FetchResult (org.eclipse.jgit.transport.FetchResult)1