GitUtils { public PullResult pull(String localPath, String token, String branch) { CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider("PRIVATE-TOKEN", token); PullResult pullResult = null; try (Git git = Git.open(new File(localPath))) { pullResult = git.pull().setRemoteBranchName(branch). setCredentialsProvider(credentialsProvider).call(); } catch (IOException e) { LOG.error(e.getMessage(), e); } catch (GitAPIException e) { LOG.error(e.getMessage(), e); } return pullResult; }  void clone(String remotePath, String localPath, String token, String branch); DirCache add(String localPath, String fileName); DirCache rm(String localPath, String fileName); void reset(String localPath, String fileName); PullResult pull(String localPath, String token, String branch); RevCommit commit(String localPath, String message); Iterable<PushResult> push(String localPath, String token, String remote); Ref branchCreate(String localPath, String branchName); List<String> branchDelete(String localPath, String branchName); Ref checkout(String localPath, String branchName); void rebase(String localPath, String branchName, String upstreamName); void remoteAdd(String localPath, String uri, String remoteName);  }
@Test public void pull() { if (token == null) { LOG.warn("Token not set!"); return; } else { gitUtils.add(LOCALPATH, "/log4j.properties"); gitUtils.commit(LOCALPATH, "add new file."); Iterable<PushResult> iterable = gitUtils.push(LOCALPATH, token, REMOTE_PATH); assertEquals(1, Lists.newArrayList(iterable).size()); PullResult pullResult = gitUtils.pull(LOCALPATH, token, "master"); assertEquals(1, pullResult.getFetchResult().getTrackingRefUpdates().size()); gitUtils.rm(LOCALPATH, "/log4j.properties"); gitUtils.commit(LOCALPATH, "add new file."); gitUtils.push(LOCALPATH, token, REMOTE_PATH); } }