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

The following examples show how to use org.eclipse.jgit.api.errors.RefNotFoundException. 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: GitWorkspaceSync.java    From milkman with MIT License 6 votes vote down vote up
private Git refreshRepository(GitSyncDetails syncDetails, File syncDir)
		throws GitAPIException, InvalidRemoteException, TransportException, IOException,
		WrongRepositoryStateException, InvalidConfigurationException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException {
	Git repo;
	if (!syncDir.exists()) {
		syncDir.mkdirs();
		repo = initWith(Git.cloneRepository(), syncDetails)
			.setURI(syncDetails.getGitUrl())
			.setDirectory(syncDir)
			.setCloneAllBranches(true)
			.setBranch("master")
			.call();
		
		
	} else {
		repo = Git.open(syncDir);
		initWith(repo.pull(), syncDetails)
			.call();
	}
	return repo;
}
 
Example #2
Source File: GitService.java    From Refactoring-Bot with MIT License 6 votes vote down vote up
/**
 * This method switches the branch.
 * 
 * @param branchName
 * @throws GitWorkflowException
 * @throws BotRefactoringException
 */
public void switchBranch(GitConfiguration gitConfig, String branchName)
		throws GitWorkflowException, BotRefactoringException {
	try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) {
		// Switch branch
		@SuppressWarnings("unused")
		Ref ref = git.checkout().setName(branchName).call();
		// If branch does not exist locally anymore
	} catch (RefNotFoundException r) {
		// Recreate branch with current branch data from remote origin
		createBranch(gitConfig, branchName, branchName, "origin");
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		throw new GitWorkflowException("Could not switch to the branch with the name " + "'" + branchName + "'!");
	}
}
 
Example #3
Source File: AppraiseReviewTaskActivationListener.java    From git-appraise-eclipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Asks the user if they want to switch to the review branch, and performs
 * the switch if so.
 */
private void promptSwitchToReviewBranch(TaskRepository taskRepository, String reviewBranch) {
  MessageDialog dialog = new MessageDialog(null, "Appraise Review", null,
      "Do you want to switch to the review branch (" + reviewBranch + ")", MessageDialog.QUESTION,
      new String[] {"Yes", "No"}, 0);
  int result = dialog.open();
  if (result == 0) {
    Repository repo = AppraisePluginUtils.getGitRepoForRepository(taskRepository);
    try (Git git = new Git(repo)) {
      previousBranch = repo.getFullBranch();
      git.checkout().setName(reviewBranch).call();
    } catch (RefNotFoundException rnfe) {
      MessageDialog alert = new MessageDialog(null, "Oops", null,
          "Branch " + reviewBranch + " not found", MessageDialog.INFORMATION, new String[] {"OK"}, 0);
      alert.open();
    } catch (Exception e) {
      AppraiseUiPlugin.logError("Unable to switch to review branch: " + reviewBranch, e);
    }
  }
}
 
Example #4
Source File: DescribedTags.java    From gradle-gitsemver with Apache License 2.0 6 votes vote down vote up
private static TagVersionAndCount fixCommitCount(TagVersionAndCount resolved, Repository repo) throws RefNotFoundException, GitAPIException {
    Git git = new Git(repo);
    ObjectId target, head;
    LogCommand logCommand;
    try {
        target = repo.getRef(resolved.getVersion()).getPeeledObjectId();
        logCommand = git.log();
        logCommand.add(target);
    } catch (IOException e) {
        throw new SemverGitflowPlugin.VersionApplicationException(e);
    }
    int count = 0;
    for (RevCommit commit : logCommand.call()) {
        count ++;
    }
    return new TagVersionAndCount(resolved.getVersion(), count);
}
 
Example #5
Source File: JGitUtil.java    From mcg-helper with Apache License 2.0 5 votes vote down vote up
public static boolean pull(String projectPath, String branch, String user, String pwd) throws IOException, WrongRepositoryStateException, InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException, RefNotAdvertisedException, NoHeadException, TransportException, GitAPIException {

		try (Git git = Git.open(new File(projectPath)) ) {
			UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider(user, pwd);
			git.pull().setRemoteBranchName(branch)
					.setCredentialsProvider(provider)
					.setProgressMonitor(new PullProgressMonitor())
					.call();
		}
		
		return true;
	}
 
Example #6
Source File: GitUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static void pull(final Git git, IProgressMonitor monitor)
		throws GitAPIException, WrongRepositoryStateException,
		InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException, TransportException {

	@SuppressWarnings("restriction")
	ProgressMonitor gitMonitor = (null == monitor) ? createMonitor()
			: new org.eclipse.egit.core.EclipseGitProgressTransformer(monitor);
	pull(git, gitMonitor);
}
 
Example #7
Source File: GitUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static void pull(final Git git, ProgressMonitor monitor)
		throws GitAPIException, WrongRepositoryStateException,
		InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException, TransportException {

	git.pull().setTransportConfigCallback(TRANSPORT_CALLBACK).setProgressMonitor(monitor).call();
}
 
Example #8
Source File: JGitEnvironmentRepositoryConcurrencyTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Override
public Ref call() throws GitAPIException, RefAlreadyExistsException,
		RefNotFoundException, InvalidRefNameException, CheckoutConflictException {
	try {
		Thread.sleep(250);
	}
	catch (InterruptedException e) {
		e.printStackTrace();
	}
	return super.call();
}
 
Example #9
Source File: DescribedTags.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
public static TagVersionAndCount resolveLatestTagVersionAndCount(
        Repository repo, TagVersionAndCount curTag, int recur) throws IOException,
        RefNotFoundException, GitAPIException {
    Git git = new Git(repo);
    String described = git.describe().setTarget(curTag.getVersion()).call();
    if (described == null)
        return null;
    TagVersionAndCount describedTag = parseDescribeOutput(described);
    if (!SemanticVersions.isValid(GitRepos.stripVFromVersionString(describedTag.getVersion()))) {
        RevWalk revWalk = new RevWalk(repo);
        RevCommit describedRev = revWalk.parseCommit(repo.resolve(describedTag.getVersion()));
        TagVersionAndCount mostRecentParentTag = new TagVersionAndCount("", Integer.MAX_VALUE);
        for (RevCommit parent : describedRev.getParents()) {
            TagVersionAndCount parentTag = new TagVersionAndCount(parent.name(), -1);
            TagVersionAndCount resolvedParentTag = resolveLatestTagVersionAndCount(repo, parentTag, recur + 1);
            if (resolvedParentTag == null)
                continue;
            if (resolvedParentTag.getCount() < mostRecentParentTag.getCount()) {
                mostRecentParentTag = resolvedParentTag;
            }
        }
        if (mostRecentParentTag.getCount() == Integer.MAX_VALUE) {
            return null;
        }
        return mostRecentParentTag;
    } else {
    	if (recur != 0)
    		return new TagVersionAndCount(describedTag.getVersion(), -1);
        return describedTag;
    }
}
 
Example #10
Source File: DescribedTags.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
public static TagVersionAndCount getLatestTagVersionAndCount(Repository repo)
        throws IOException, RefNotFoundException, GitAPIException {
	TagVersionAndCount tac = resolveLatestTagVersionAndCount(repo, new TagVersionAndCount("HEAD", 0), 0);
	if (tac.getCount() == -1)
		return fixCommitCount(tac, repo);
	return tac;
}
 
Example #11
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
private static Git initializeGitFlow(Repository repo)
        throws RefAlreadyExistsException, RefNotFoundException,
        InvalidRefNameException, GitAPIException {
    Git git = new Git(repo);
    git.commit().setCommitter(COMMITTER).setMessage("initial commit").call();
    return git;
}
 
Example #12
Source File: GitUtils.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private static void pull(final Git git) throws GitAPIException, WrongRepositoryStateException,
		InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException, TransportException {

	pull(git, (ProgressMonitor) null);
}
 
Example #13
Source File: MavenIntegrationTest.java    From gitflow-incremental-builder with MIT License 4 votes vote down vote up
private void checkoutDevelop() throws GitAPIException, CheckoutConflictException, RefAlreadyExistsException,
        RefNotFoundException, InvalidRefNameException {
    Git git = localRepoMock.getGit();
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
    git.checkout().setName("develop").call();
}
 
Example #14
Source File: GitControl.java    From juneau with Apache License 2.0 4 votes vote down vote up
public void branch(String name) throws RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
		CheckoutConflictException, GitAPIException {
	git.checkout().setName(name).setStartPoint("origin/".concat(name)).call();
}
 
Example #15
Source File: GitControl.java    From juneau with Apache License 2.0 4 votes vote down vote up
public void pullFromRepo()
		throws IOException, WrongRepositoryStateException, InvalidConfigurationException, DetachedHeadException,
		InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException, GitAPIException {
	git.pull().call();
}