private boolean internalTest()

in org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/RepositoriesViewPropertyTester.java [72:179]


	private boolean internalTest(RepositoryTreeNode node, Repository repository,
			String property) {
		if (property.equals("isBare")) { //$NON-NLS-1$
			return repository.isBare();
		}

		if (property.equals("containsHead")) {//$NON-NLS-1$
			return containsHead(repository);
		}

		if (ResourcePropertyTester.testRepositoryState(repository, property)) {
			return true;
		}

		if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$
			if (node instanceof BranchHierarchyNode) {
				try {
					for (Ref ref : ((BranchHierarchyNode) node)
							.getChildRefsRecursive()) {
						if (isRefCheckedOut(repository, ref)) {
							return true;
						}
					}
				} catch (IOException e) {
					return false;
				}
			}
			if (!(node.getObject() instanceof Ref)) {
				return false;
			}
			Ref ref = (Ref) node.getObject();
			return isRefCheckedOut(repository, ref);
		}
		if (property.equals("isLocalBranch")) { //$NON-NLS-1$
			if (!(node.getObject() instanceof Ref)) {
				return false;
			}
			Ref ref = (Ref) node.getObject();
			return ref.getName().startsWith(Constants.R_HEADS);
		}
		if (property.equals("fetchExists")) { //$NON-NLS-1$
			if (node instanceof RemoteNode) {
				String configName = ((RemoteNode) node).getObject();

				RemoteConfig rconfig;
				try {
					rconfig = new RemoteConfig(
							SelectionRepositoryStateCache.INSTANCE.getConfig(repository),
							configName);
				} catch (URISyntaxException e2) {
					return false;
				}
				// we need to have a fetch ref spec and a fetch URI
				return !rconfig.getFetchRefSpecs().isEmpty()
						&& !rconfig.getURIs().isEmpty();
			}
		}
		if (property.equals("pushExists")) { //$NON-NLS-1$
			if (node instanceof RemoteNode) {
				String configName = ((RemoteNode) node).getObject();

				RemoteConfig rconfig;
				try {
					rconfig = new RemoteConfig(
							SelectionRepositoryStateCache.INSTANCE.getConfig(repository),
							configName);
				} catch (URISyntaxException e2) {
					return false;
				}
				// we need to have at least a push ref spec and any URI
				return !rconfig.getPushRefSpecs().isEmpty()
						&& (!rconfig.getPushURIs().isEmpty() || !rconfig
								.getURIs().isEmpty());
			}
		}
		if (property.equals("canStash")) { //$NON-NLS-1$
			RepositoryState state = SelectionRepositoryStateCache.INSTANCE
					.getRepositoryState(repository);
			return state.canCommit();
		}
		if (property.equals("canMerge")) { //$NON-NLS-1$
			RepositoryState state = SelectionRepositoryStateCache.INSTANCE
					.getRepositoryState(repository);
			if (state != RepositoryState.SAFE) {
				return false;
			}
			String branch = SelectionRepositoryStateCache.INSTANCE
					.getFullBranchName(repository);
			if (branch == null) {
				return false; // fail gracefully...
			}
			return branch.startsWith(Constants.R_HEADS);
		}

		if ("isSubmodule".equals(property)) { //$NON-NLS-1$
			RepositoryTreeNode<?> parent = node.getParent();
			return parent != null
					&& parent.getType() == RepositoryTreeNodeType.SUBMODULES;
		}

		if ("canEnableLfs".equals(property)) { //$NON-NLS-1$
			if (LfsFactory.getInstance().isAvailable()) {
				return !LfsFactory.getInstance().isEnabled(repository);
			}
		}

		return false;
	}