org.eclipse.jgit.errors.RepositoryNotFoundException Java Examples
The following examples show how to use
org.eclipse.jgit.errors.RepositoryNotFoundException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedHttpGitServer.java From smart-testing with Apache License 2.0 | 8 votes |
private GitServlet createGitServlet() { final GitServlet gitServlet = new GitServlet(); gitServlet.setRepositoryResolver((req, name) -> { String trimmedName = name.endsWith(SUFFIX) ? name.substring(0, name.length() - SUFFIX.length()) : name; trimmedName = trimmedName.substring(trimmedName.lastIndexOf('/') + 1); if (repositories.containsKey(trimmedName)) { final LazilyLoadedRepository lazilyLoadedRepository = repositories.get(trimmedName); synchronized (gitServlet) { lazilyLoadedRepository.cloneRepository(); final Repository repository = lazilyLoadedRepository.get(); enableInsecureReceiving(repository); repository.incrementOpen(); return repository; } } else { throw new RepositoryNotFoundException("Repository " + name + "does not exist"); } }); gitServlet.addReceivePackFilter(new AfterReceivePackResetFilter(repositories.values())); return gitServlet; }
Example #2
Source File: BackupService.java From app-runner with MIT License | 7 votes |
public static BackupService prepare(File localDir, URIish remoteUri, int backupTimeInMinutes) throws GitAPIException, IOException { Git local; try { local = Git.open(localDir); } catch (RepositoryNotFoundException e) { log.info("Initialising " + fullPath(localDir) + " as a git repo for backup purposes"); local = Git.init().setDirectory(localDir).setBare(false).call(); } log.info("Setting backup URL to " + remoteUri); if (local.remoteList().call().stream().anyMatch(remoteConfig -> remoteConfig.getName().equals("origin"))) { RemoteSetUrlCommand remoteSetUrlCommand = local.remoteSetUrl(); remoteSetUrlCommand.setRemoteName("origin"); remoteSetUrlCommand.setRemoteUri(remoteUri); remoteSetUrlCommand.call(); } else { RemoteAddCommand remoteAddCommand = local.remoteAdd(); remoteAddCommand.setName("origin"); remoteAddCommand.setUri(remoteUri); remoteAddCommand.call(); } URL inputUrl = BackupService.class.getResource("/dataDirGitIgnore.txt"); FileUtils.copyURLToFile(inputUrl, new File(localDir, ".gitignore")); return new BackupService(local, remoteUri.toString(), backupTimeInMinutes); }
Example #3
Source File: PluginRepoResolver.java From flow-platform-x with Apache License 2.0 | 6 votes |
@Override public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException { try { Plugin plugin = pluginService.get(name); File gitDir = Paths.get(pluginService.getDir(plugin).toString(), ".git").toFile(); return new FileRepository(gitDir); } catch (NotFoundException | IOException e) { throw new RepositoryNotFoundException("Repository " + name + "does not exist"); } }
Example #4
Source File: AppNameResolver.java From heroku-maven-plugin with MIT License | 6 votes |
private static Optional<String> resolveViaHerokuGitRemote(Path rootDirectory) throws IOException { try { Git gitRepo = Git.open(rootDirectory.toFile()); Config config = gitRepo.getRepository().getConfig(); for (String remoteName : config.getSubsections("remote")) { String remoteUrl = config.getString("remote", remoteName, "url"); for (Pattern gitRemoteUrlAppNamePattern : GIT_REMOTE_URL_APP_NAME_PATTERNS) { Matcher matcher = gitRemoteUrlAppNamePattern.matcher(remoteUrl); if (matcher.matches()) { return Optional.of(matcher.group(1)); } } } } catch (RepositoryNotFoundException e) { return Optional.empty(); } return Optional.empty(); }
Example #5
Source File: GitUtils.java From halo with GNU General Public License v3.0 | 5 votes |
public static Git openOrInit(Path repoPath) throws IOException, GitAPIException { Git git; try { git = Git.open(repoPath.toFile()); } catch (RepositoryNotFoundException e) { log.warn("Git repository may not exist, we will try to initialize an empty repository", e); git = Git.init().setDirectory(repoPath.toFile()).call(); } return git; }
Example #6
Source File: PluginRepoResolver.java From flow-platform-x with Apache License 2.0 | 5 votes |
@Override public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException { try { Plugin plugin = pluginService.get(name); File gitDir = Paths.get(pluginService.getDir(plugin).toString(), ".git").toFile(); return new FileRepository(gitDir); } catch (NotFoundException | IOException e) { throw new RepositoryNotFoundException("Repository " + name + "does not exist"); } }
Example #7
Source File: GitUtils.java From heroku-maven-plugin with MIT License | 5 votes |
public static Optional<String> getHeadCommitHash(Path projectDirectory) throws IOException { try { Git git = Git.open(projectDirectory.toFile()); ObjectId objectId = git.getRepository().resolve(Constants.HEAD); return Optional.of(objectId.getName()); } catch (RepositoryNotFoundException e) { return Optional.empty(); } }
Example #8
Source File: Bridge.java From writelatex-git-bridge with MIT License | 5 votes |
/** * Synchronises the given repository with Overleaf. * * It acquires the project lock and calls * {@link #getUpdatedRepoCritical(Optional, String)}. * @param oauth2 The oauth2 to use * @param projectName The name of the project * @throws IOException * @throws GitUserException */ public ProjectRepo getUpdatedRepo( Optional<Credential> oauth2, String projectName ) throws IOException, GitUserException { try (LockGuard __ = lock.lockGuard(projectName)) { if (!snapshotAPI.projectExists(oauth2, projectName)) { throw new RepositoryNotFoundException(projectName); } Log.info("[{}] Updating repository", projectName); return getUpdatedRepoCritical(oauth2, projectName); } }
Example #9
Source File: WrapGit.java From jphp with Apache License 2.0 | 5 votes |
@Signature public void __construct(File directory, boolean create) throws IOException, GitAPIException { try { __wrappedObject = Git.open(directory, FS.DETECTED); } catch (RepositoryNotFoundException e) { if (create) { Git.init().setBare(false).setDirectory(directory).call(); __wrappedObject = Git.open(directory, FS.DETECTED); } } }
Example #10
Source File: GitTest.java From halo with GNU General Public License v3.0 | 4 votes |
@Test(expected = RepositoryNotFoundException.class) public void openFailureTest() throws IOException { Git.open(tempPath.toFile()); }
Example #11
Source File: LocalGitRepo.java From multi-module-maven-release-plugin with MIT License | 4 votes |
/** * Uses the current working dir to open the Git repository. * @throws ValidationException if anything goes wrong */ public LocalGitRepo buildFromCurrentDir() throws ValidationException { Git git; File gitDir = new File("."); try { git = Git.open(gitDir); } catch (RepositoryNotFoundException rnfe) { String fullPathOfCurrentDir = pathOf(gitDir); File gitRoot = getGitRootIfItExistsInOneOfTheParentDirectories(new File(fullPathOfCurrentDir)); String summary; List<String> messages = new ArrayList<String>(); if (gitRoot == null) { summary = "Releases can only be performed from Git repositories."; messages.add(summary); messages.add(fullPathOfCurrentDir + " is not a Git repository."); } else { summary = "The release plugin can only be run from the root folder of your Git repository"; messages.add(summary); messages.add(fullPathOfCurrentDir + " is not the root of a Git repository"); messages.add("Try running the release plugin from " + pathOf(gitRoot)); } throw new ValidationException(summary, messages); } catch (Exception e) { throw new ValidationException("Could not open git repository. Is " + pathOf(gitDir) + " a git repository?", Arrays.asList("Exception returned when accessing the git repo:", e.toString())); } TagFetcher tagFetcher; TagPusher tagPusher; if (operationsAllowed.contains(GitOperations.PULL_TAGS)) { tagFetcher = new RemoteTagFetcher(git, remoteGitUrl, credentialsProvider); } else { tagFetcher = new LocalTagFetcher(git); } if (operationsAllowed.contains(GitOperations.PUSH_TAGS)) { tagPusher = new RemoteTagPusher(git, remoteGitUrl, credentialsProvider); } else { tagPusher = new LocalTagPusher(git); } return new LocalGitRepo(git, tagFetcher, tagPusher); }