SyncRemote { void fillBranches(final List<Ref> branches, final Collection<String> remoteBranches, final Collection<String> localBranches) { for (final Ref branch : branches) { final String branchFullName = branch.getName(); final String remotePrefix = "refs/remotes/" + remote.getK1() + "/"; final String localPrefix = "refs/heads/"; if (branchFullName.startsWith(remotePrefix)) { remoteBranches.add(branchFullName.replaceFirst(remotePrefix, "")); } else if (branchFullName.startsWith(localPrefix)) { localBranches.add(branchFullName.replaceFirst(localPrefix, "")); } else { localBranches.add(branchFullName.substring(branchFullName.lastIndexOf("/") + 1)); } } } SyncRemote(final GitImpl git,
                      final Pair<String, String> remote); Optional execute();  }
@Test public void fillBranchesTest() { final List<Ref> branches = Arrays.asList(createBranch("refs/heads/local/branch1"), createBranch("refs/heads/localBranch2"), createBranch("refs/remotes/upstream/remote/branch1"), createBranch("refs/remotes/upstream/remoteBranch2")); final List<String> remoteBranches = new ArrayList<>(); final List<String> localBranches = new ArrayList<>(); syncRemote.fillBranches(branches, remoteBranches, localBranches); assertEquals(2, remoteBranches.size()); assertEquals("remote/branch1", remoteBranches.get(0)); assertEquals("remoteBranch2", remoteBranches.get(1)); assertEquals(2, localBranches.size()); assertEquals("local/branch1", localBranches.get(0)); assertEquals("localBranch2", localBranches.get(1)); }