org.eclipse.jgit.api.errors.JGitInternalException Java Examples

The following examples show how to use org.eclipse.jgit.api.errors.JGitInternalException. 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 Project: netbeans   Author: apache   File: SubmoduleStatusCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    File workTree = repository.getWorkTree();
    org.eclipse.jgit.api.SubmoduleStatusCommand cmd = new Git(repository).submoduleStatus();
    for (String path : Utils.getRelativePaths(workTree, roots)) {
        cmd.addPath(path);
    }
    try {
        Map<String, SubmoduleStatus> result = cmd.call();
        GitClassFactory fac = getClassFactory();
        for (Map.Entry<String, SubmoduleStatus> e : result.entrySet()) {
            File root = new File(workTree, e.getKey());
            statuses.put(root, fac.createSubmoduleStatus(e.getValue(), root));
        }
    } catch (GitAPIException | JGitInternalException ex) {
        throw new GitException(ex);
    }
}
 
Example #2
Source Project: netbeans   Author: apache   File: CreateTagCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    try {
        RevObject obj = Utils.findObject(repository, taggedObject);
        TagCommand cmd = new Git(repository).tag();
        cmd.setName(tagName);
        cmd.setForceUpdate(forceUpdate);
        cmd.setObjectId(obj);
        cmd.setAnnotated(message != null && !message.isEmpty() || signed);
        if (cmd.isAnnotated()) {
            cmd.setMessage(message);
            cmd.setSigned(signed);
        }
        cmd.call();
        ListTagCommand tagCmd = new ListTagCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor));
        tagCmd.run();
        Map<String, GitTag> tags = tagCmd.getTags();
        tag = tags.get(tagName);
    } catch (JGitInternalException | GitAPIException ex) {
        throw new GitException(ex);
    }
}
 
Example #3
Source Project: netbeans   Author: apache   File: SubmoduleInitializeCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    File workTree = repository.getWorkTree();
    org.eclipse.jgit.api.SubmoduleInitCommand cmd = new Git(repository).submoduleInit();
    for (String path : Utils.getRelativePaths(workTree, roots)) {
        cmd.addPath(path);
    }
    try {
        cmd.call();
        statusCmd.run();
    } catch (GitAPIException | JGitInternalException ex) {
        throw new GitException(ex);
    }
}
 
Example #4
Source Project: orion.server   Author: eclipse   File: StashApplyCommand.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void checkoutPath(DirCacheEntry entry, ObjectReader reader) {
	try {
		DirCacheCheckout.checkoutEntry(repo, entry, reader);
	} catch (IOException e) {
		throw new JGitInternalException(MessageFormat.format(JGitText.get().checkoutConflictWithFile, entry.getPathString()), e);
	}
}
 
Example #5
Source Project: orion.server   Author: eclipse   File: GitJob.java    License: Eclipse Public License 1.0 5 votes vote down vote up
IStatus getJGitInternalExceptionStatus(JGitInternalException e, String message) {
	IStatus status = getExceptionStatus(e, message);
	// TODO uncomment this when fix in jgit is merged
	// if (status instanceof ServerStatus) {
	// LogHelper.log(new Status(IStatus.WARNING, GitActivator.PI_GIT,
	// "JGitInternalException should not be thrown for authentication errors. See https://git.eclipse.org/r/#/c/6207/", e));
	// }
	return status;
}
 
Example #6
Source Project: mdw   Author: CenturyLinkCloud   File: VersionControlGit.java    License: Apache License 2.0 5 votes vote down vote up
public void fetch() throws Exception {
    if (allowFetch) {
        FetchCommand fetchCommand = git.fetch().setRemoveDeletedRefs(true);
        if (credentialsProvider != null)
            fetchCommand.setCredentialsProvider(credentialsProvider);
        try {
            fetchCommand.call();
        }
        catch (JGitInternalException | TransportException ex) {
            // LocalRepo object might be out of sync with actual local repo, so recreate objects for next time
            reconnect();
            throw ex;
        }
    }
}
 
Example #7
Source Project: juneau   Author: apache   File: GitControl.java    License: Apache License 2.0 5 votes vote down vote up
public void pushToRepo() throws IOException, JGitInternalException, InvalidRemoteException, GitAPIException {
	PushCommand pc = git.push();
	pc.setCredentialsProvider(cp).setForce(true).setPushAll();
	try {
		Iterator<PushResult> it = pc.call().iterator();
		if (it.hasNext()) {
			System.out.println(it.next().toString());
		}
	} catch (InvalidRemoteException e) {
		e.printStackTrace();
	}
}
 
Example #8
Source Project: git-client-plugin   Author: jenkinsci   File: JGitAPIImpl.java    License: MIT License 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boolean headsOnly, boolean tagsOnly)
        throws GitException, InterruptedException {
    Map<String, ObjectId> references = new HashMap<>();
    String regexPattern = null;
    if (pattern != null) {
        regexPattern = createRefRegexFromGlob(pattern);
    }
    try (Repository repo = openDummyRepository()) {
        LsRemoteCommand lsRemote = new LsRemoteCommand(repo);
        if (headsOnly) {
            lsRemote.setHeads(headsOnly);
        }
        if (tagsOnly) {
            lsRemote.setTags(tagsOnly);
        }
        lsRemote.setRemote(url);
        lsRemote.setCredentialsProvider(getProvider());
        Collection<Ref> refs = lsRemote.call();
            for (final Ref r : refs) {
                final String refName = r.getName();
                final ObjectId refObjectId =
                        r.getPeeledObjectId() != null ? r.getPeeledObjectId() : r.getObjectId();
                if (regexPattern != null) {
                    if (refName.matches(regexPattern)) {
                        references.put(refName, refObjectId);
                    }
                } else {
                    references.put(refName, refObjectId);
                }
            }
    } catch (JGitInternalException | GitAPIException | IOException e) {
        throw new GitException(e);
    }
    return references;
}
 
Example #9
Source Project: git-client-plugin   Author: jenkinsci   File: GitExceptionTest.java    License: MIT License 5 votes vote down vote up
@Test
public void initJGitImplThrowsGitException() throws GitAPIException, IOException, InterruptedException {
    String fileName = isWindows() ? "\\\\badserver\\badshare\\bad\\dir" : "/this/is/a/bad/dir";
    final File badDirectory = new File(fileName);
    assumeFalse("running as root?", new File("/").canWrite());
    GitClient defaultClient = Git.with(TaskListener.NULL, new EnvVars()).in(badDirectory).using("jgit").getClient();
    assertNotNull(defaultClient);
    JGitInternalException e = assertThrows(JGitInternalException.class,
                                           () -> {
                                               defaultClient.init_().workspace(badDirectory.getAbsolutePath()).execute();
                                           });
    assertThat(e.getCause(), isA(IOException.class));
}
 
Example #10
Source Project: git-client-plugin   Author: jenkinsci   File: GitExceptionTest.java    License: MIT License 5 votes vote down vote up
@Test
public void initJGitImplCollisionThrowsGitException() throws GitAPIException, IOException, InterruptedException {
    File dir = folder.getRoot();
    File dotGit = folder.newFile(".git");
    Files.write(dotGit.toPath(), "file named .git".getBytes("UTF-8"), APPEND);
    GitClient defaultClient = Git.with(TaskListener.NULL, new EnvVars()).in(dir).using("jgit").getClient();
    JGitInternalException e = assertThrows(JGitInternalException.class,
                                           () -> {
                                               defaultClient.init_().workspace(dir.getAbsolutePath()).execute();
                                           });
    assertThat(e.getCause(), isA(IOException.class));
}
 
Example #11
Source Project: git-client-plugin   Author: jenkinsci   File: GitClientTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testInitFailureNotWindowsNotSuperUser() throws Exception {
    assumeFalse(isWindows());
    assumeFalse("running as root?", new File("/").canWrite());
    String badDirName = "/this/directory/is/not/accessible";
    File badDir = new File(badDirName);
    GitClient badGitClient = Git.with(TaskListener.NULL, new EnvVars()).in(badDir).using(gitImplName).getClient();
    Class expectedExceptionClass = gitImplName.equals("git") ? GitException.class : JGitInternalException.class;
    assertThrows(expectedExceptionClass,
                 () -> {
                     badGitClient.init_().bare(random.nextBoolean()).workspace(badDirName).execute();
                 });
}
 
Example #12
Source Project: git-client-plugin   Author: jenkinsci   File: GitClientTest.java    License: MIT License 5 votes vote down vote up
@Issue("JENKINS-35687") // Git LFS support - JGit not supported
@Test(expected = org.eclipse.jgit.api.errors.JGitInternalException.class)
public void testCheckoutWithJGitLFS() throws Exception {
    assumeThat(gitImplName, startsWith("jgit"));
    assumeTrue(CLI_GIT_HAS_GIT_LFS);
    String branch = "tests/largeFileSupport";
    String remote = fetchLFSTestRepo(branch);
    gitClient.checkout().branch(branch).ref(remote + "/" + branch).lfsRemote(remote).execute();
}
 
Example #13
Source Project: git-client-plugin   Author: jenkinsci   File: GitClientTest.java    License: MIT License 5 votes vote down vote up
@Issue("JENKINS-35687") // Git LFS support
@Test(expected = org.eclipse.jgit.api.errors.JGitInternalException.class)
public void testJGitCheckoutWithoutLFSWhenLFSAvailable() throws Exception {
    assumeThat(gitImplName, startsWith("jgit"));
    assumeTrue(CLI_GIT_HAS_GIT_LFS);
    String branch = "tests/largeFileSupport";
    String remote = fetchLFSTestRepo(branch);
    gitClient.checkout().branch(branch).ref(remote + "/" + branch).execute();
}
 
Example #14
Source Project: netbeans   Author: apache   File: CherryPickCommand.java    License: Apache License 2.0 4 votes vote down vote up
private void applySteps (List<RebaseTodoLine> steps, boolean skipFirstStep) throws GitAPIException, IOException {
    Repository repository = getRepository();
    ObjectReader or = repository.newObjectReader();
    CherryPickResult res = null;
    boolean skipped = false;
    List<Ref> cherryPickedRefs = new ArrayList<>();
    for (Iterator<RebaseTodoLine> it = steps.iterator(); it.hasNext();) {
        RebaseTodoLine step = it.next();
        if (step.getAction() == RebaseTodoLine.Action.PICK) {
            if (skipFirstStep && !skipped) {
                it.remove();
                writeTodoFile(repository, steps);
                skipped = true;
                continue;
            }
            Collection<ObjectId> ids = or.resolve(step.getCommit());
            if (ids.size() != 1) {
                throw new JGitInternalException("Could not resolve uniquely the abbreviated object ID");
            }
            org.eclipse.jgit.api.CherryPickCommand command = new Git(repository).cherryPick();
            command.include(ids.iterator().next());
            if (workAroundStrategyIssue) {
                command.setStrategy(new FailuresDetectRecurciveStrategy());
            }
            res = command.call();
            if (res.getStatus() == CherryPickResult.CherryPickStatus.OK) {
                it.remove();
                writeTodoFile(repository, steps);
                cherryPickedRefs.addAll(res.getCherryPickedRefs());
            } else {
                break;
            }
        } else {
            it.remove();
        }
    }
    if (res == null) {
        result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK, cherryPickedRefs);
    } else {
        result = createResult(res, cherryPickedRefs);
    }
    if (steps.isEmpty()) {
        // sequencer no longer needed
        Utils.deleteRecursively(getSequencerFolder());
    }
}
 
Example #15
Source Project: orion.server   Author: eclipse   File: LogCommand.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Executes the {@code Log} command with all the options and parameters collected by the setter methods (e.g. {@link #add(AnyObjectId)},
 * {@link #not(AnyObjectId)}, ..) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method
 * twice on an instance.
 *
 * @return an iteration over RevCommits
 * @throws NoHeadException
 *             of the references ref cannot be resolved
 */
@Override
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException {
	checkCallable();
	ArrayList<RevFilter> filters = new ArrayList<RevFilter>();

	if (pathFilters.size() > 0)
		walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF));

	if (msgFilter != null)
		filters.add(msgFilter);
	if (authorFilter != null)
		filters.add(authorFilter);
	if (committerFilter != null)
		filters.add(committerFilter);
	if (sha1Filter != null)
		filters.add(sha1Filter);
	if (dateFilter != null)
		filters.add(dateFilter);
	if (skip > -1)
		filters.add(SkipRevFilter.create(skip));
	if (maxCount > -1)
		filters.add(MaxCountRevFilter.create(maxCount));
	RevFilter filter = null;
	if (filters.size() > 1) {
		filter = AndRevFilter.create(filters);
	} else if (filters.size() == 1) {
		filter = filters.get(0);
	}

	if (filter != null)
		walk.setRevFilter(filter);

	if (!startSpecified) {
		try {
			ObjectId headId = repo.resolve(Constants.HEAD);
			if (headId == null)
				throw new NoHeadException(JGitText.get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified);
			add(headId);
		} catch (IOException e) {
			// all exceptions thrown by add() shouldn't occur and represent
			// severe low-level exception which are therefore wrapped
			throw new JGitInternalException(JGitText.get().anExceptionOccurredWhileTryingToAddTheIdOfHEAD, e);
		}
	}
	setCallable(false);
	return walk;
}
 
Example #16
Source Project: WebIDE-Backend   Author: Coding   File: ExceptionAdvice.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExceptionHandler(JGitInternalException.class)
@ResponseStatus(INTERNAL_SERVER_ERROR)
@ResponseBody
public JsonObject jGitInternalErrors(JGitInternalException e) {
    return makeMsg(e);
}
 
Example #17
Source Project: juneau   Author: apache   File: GitControl.java    License: Apache License 2.0 4 votes vote down vote up
public void commitToRepo(String message) throws IOException, NoHeadException, NoMessageException,
		ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException, GitAPIException {
	git.commit().setMessage(message).call();
}