GitPathUtil { public static Optional<String> extractBranchFromRef(final String refName) { final Matcher matcher = branchNameExtractorFromRef.matcher(refName); if (matcher.matches()) { return Optional.of(matcher.group(1)); } else { return Optional.empty(); } }  static Optional<String> extractBranch(final String uri); static Optional<String> extractBranchFromRef(final String refName);  }
@Test public void extractLocalBranchNameFromRef() throws Exception { final Optional<String> result = GitPathUtil.extractBranchFromRef("refs/heads/master"); assertEquals("master", result.get()); }
@Test public void extractLocalBranchNameWithSlashFromRef() throws Exception { final Optional<String> result = GitPathUtil.extractBranchFromRef("refs/heads/my/branch"); assertEquals("my/branch", result.get()); }
@Test public void extractRemoteBranchNameFromRef() throws Exception { final Optional<String> result = GitPathUtil.extractBranchFromRef("refs/remotes/upstream/master"); assertEquals("master", result.get()); }
@Test public void extractRemoteBranchNameWithSlashFromRef() throws Exception { final Optional<String> result = GitPathUtil.extractBranchFromRef("refs/remotes/upstream/my/branch"); assertEquals("my/branch", result.get()); }