private Branch getBranch(final Repository repository, final Path convertedPath) { for (final Branch branch : repository.getBranches()) { if (branch.getPath().equals(convertedPath)) { return branch; } } return null; }
@Override public Optional<Branch> getBranch(Path branchRoot) { for (final Branch branch : getBranches()) { if (branch.getPath().equals(branchRoot)) { return Optional.of(branch); } } return Optional.empty(); }
/** * Short cut for the WorkspaceProject root. * @return The root path of the active branch. */ public Path getRootPath() { return this.getBranch().getPath(); }
@Override public WorkspaceProject resolveProject(final Space space, final Branch branch) { return resolveProject(space, branch.getPath()); }
private Branch resolveBranch(final org.uberfire.java.nio.file.Path repositoryRoot, final Repository repository) { final Branch defaultBranch = repository.getDefaultBranch().get(); if (!Paths.convert(defaultBranch.getPath()).equals(repositoryRoot)) { for (final Branch branch : repository.getBranches()) { if (Paths.convert(branch.getPath()).equals(repositoryRoot)) { return branch; } } } return defaultBranch; }
private Branch resolveBranch(final org.uberfire.java.nio.file.Path repositoryRoot, final Repository repository) { final Branch defaultBranch = repository.getDefaultBranch().get(); if (!Paths.convert(defaultBranch.getPath()).equals(repositoryRoot)) { for (final Branch branch : repository.getBranches()) { if (Paths.convert(branch.getPath()).equals(repositoryRoot)) { return branch; } } } return defaultBranch; }
public void onArchiveActiveRepository() { final Optional<Branch> defaultBranch = context.getActiveWorkspaceProject() .map(proj -> proj.getRepository()) .orElseThrow(() -> new IllegalStateException("Cannot check for default branch without an active project.")) .getDefaultBranch(); if (defaultBranch.isPresent()) { view.archive(defaultBranch.get().getPath()); } }
public Set<Module> find() { if (branch == null) { return modules; } findModule(Paths.convert(branch.getPath()), true); return modules; }
public Set<Module> find() { if (branch == null) { return modules; } findModule(Paths.convert(branch.getPath()), true); return modules; }
private String getNiogitRepoPath(Repository repository) { final Branch branch = repository.getDefaultBranch().get(); final Path path = pathUtil.convert(branch.getPath()); return pathUtil.getNiogitRepoPath(path); }
public void add(Repository repository) { repositoriesByAlias.put(repository.getAlias(), repository); if (repository.getBranches() != null) { for (final Branch branch : repository.getBranches()) { repositoriesByBranchRoot.put(Paths.normalizePath(branch.getPath()), repository); } } }
public Module get(final OrganizationalUnit organizationalUnit, final Repository repository) { if (organizationalUnit == null || repository == null || !repository.getDefaultBranch().isPresent()) { return null; } final Object obj = content.get(Pair.newPair(organizationalUnit.getName(), repository.getDefaultBranch().get().getPath()).toString()); if (obj != null && obj instanceof Module) { return (Module) obj; } return null; }
public void addModule(final OrganizationalUnit organizationalUnit, final Repository repository, final Module module) { if (repository.getDefaultBranch().isPresent()) { final String key = Pair.newPair(organizationalUnit.getName(), repository.getDefaultBranch().get().getPath()).toString(); content.put(key, module); indexRepository(repository, key); } }
public void onNewBranch(final @Observes NewBranchEvent event) { for (final GuvnorStructureContextChangeHandler handler : handlers.values()) { final Optional<Branch> branchOptional = event.getRepository().getBranch(event.getNewBranchName()); if (branchOptional.isPresent()) { handler.onNewBranchAdded(event.getRepository().getAlias(), event.getNewBranchName(), branchOptional.get().getPath()); } } }
private void setUpMasterBranch() { final HashSet<Module> masterBranchModules = new HashSet<>(); final Module mockModule = mockModule("legacyProject1", legacyMasterBranchProject1RootPath); masterBranchModules.add(mockModule); doReturn(masterBranchModules).when(moduleService).getAllModules(legacyMasterBranch); final Path masterRoot = mock(Path.class); when(legacyMasterBranch.getPath()).thenReturn(masterRoot); }
protected void cleanupOrigin(Repository repository) { try { // AF-1715: Cleaning origin to prevent errors while importing the new generated repo. Git git = ((JGitPathImpl) pathUtil.convert(repository.getDefaultBranch().get().getPath())).getFileSystem().getGit(); new RemoveRemote(git,"origin",REMOTE_ORIGIN_REF).execute(); } catch (GitException e) { log.warn("Error cleaning up origin for repository '{}': {}", repository.getAlias(), e); } }
@Override public void removeBranch(final WorkspaceProject project, final Branch branch) { final org.uberfire.java.nio.file.Path branchPath = pathUtil.convert(branch.getPath()); ioService.delete(branchPath); configuredRepositories.refreshRepository(project.getRepository()); }
@Test public void getRootPath() { final Branch branch = mock(Branch.class); final Path branchPath = mock(Path.class); when(branch.getPath()).thenReturn(branchPath); final WorkspaceProject workspaceProject = new WorkspaceProject(mock(OrganizationalUnit.class), mock(Repository.class), branch, mock(Module.class)); assertEquals(branchPath, workspaceProject.getRootPath()); }
@Override public List<FileDiff> diff(final PullRequest pullRequest) { final Repository repository = repositoryService.getRepositoryFromSpace(spaces.getSpace(pullRequest.getTargetSpace()), pullRequest.getTargetRepository()); this.createHiddenBranch(pullRequest); String diff = String.format("diff:%s,%s", pullRequest.getTargetBranch(), this.buildHiddenBranchName(pullRequest)); final List<FileDiff> diffs = (List<FileDiff>) this.ioService.readAttributes(convert(repository.getBranch(pullRequest.getSourceBranch()).get().getPath()), diff); this.deleteHiddenBranch(pullRequest); return diffs; }
@Test public void testBranches() throws Exception { rootDirectories.add(createPath("default://origin@uf-playground")); rootDirectories.add(createPath("default://master@uf-playground")); rootDirectories.add(createPath("default://branch1@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); Repository repository = helper.newRepository(configGroup); assertEquals(3, repository.getBranches().size()); assertTrue(repository.getDefaultBranch().get().getPath().toURI().contains("master")); }