List of usage examples for org.eclipse.jgit.api Git open
public static Git open(File dir) throws IOException
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
public ChangeSet getHead() { Git git = null;//from w w w.j a va 2 s.c o m try { git = Git.open(new File(path)); ObjectId head = git.getRepository().resolve(Constants.HEAD); RevWalk revWalk = new RevWalk(git.getRepository()); RevCommit r = revWalk.parseCommit(head); return new ChangeSet(r.getName(), convertToDate(r)); } catch (Exception e) { throw new RuntimeException("error in getHead() for " + path, e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public List<ChangeSet> getChangeSets() { Git git = null;//from www .j a va 2s .c o m try { git = Git.open(new File(path)); List<ChangeSet> allCs = new ArrayList<ChangeSet>(); for (RevCommit r : git.log().all().call()) { String hash = r.getName(); GregorianCalendar date = convertToDate(r); allCs.add(new ChangeSet(hash, date)); } return allCs; } catch (Exception e) { throw new RuntimeException("error in getChangeSets for " + path, e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public Commit getCommit(String id) { Git git = null;/* ww w . ja v a 2 s . com*/ try { git = Git.open(new File(path)); Repository repo = git.getRepository(); Iterable<RevCommit> commits = git.log().add(repo.resolve(id)).call(); Commit theCommit = null; for (RevCommit jgitCommit : commits) { Developer author = new Developer(jgitCommit.getAuthorIdent().getName(), jgitCommit.getAuthorIdent().getEmailAddress()); Developer committer = new Developer(jgitCommit.getCommitterIdent().getName(), jgitCommit.getCommitterIdent().getEmailAddress()); String msg = jgitCommit.getFullMessage().trim(); String hash = jgitCommit.getName().toString(); long epoch = jgitCommit.getCommitTime(); String parent = (jgitCommit.getParentCount() > 0) ? jgitCommit.getParent(0).getName().toString() : ""; GregorianCalendar date = new GregorianCalendar(); date.setTime(new Date(epoch * 1000L)); theCommit = new Commit(hash, author, committer, date, msg, parent); List<DiffEntry> diffsForTheCommit = diffsForTheCommit(repo, jgitCommit); if (diffsForTheCommit.size() > MAX_NUMBER_OF_FILES_IN_A_COMMIT) { log.error("commit " + id + " has more than files than the limit"); throw new RuntimeException("commit " + id + " too big, sorry"); } for (DiffEntry diff : diffsForTheCommit) { ModificationType change = Enum.valueOf(ModificationType.class, diff.getChangeType().toString()); String oldPath = diff.getOldPath(); String newPath = diff.getNewPath(); String diffText = ""; String sc = ""; if (diff.getChangeType() != ChangeType.DELETE) { diffText = getDiffText(repo, diff); sc = getSourceCode(repo, diff); } if (diffText.length() > MAX_SIZE_OF_A_DIFF) { log.error("diff for " + newPath + " too big"); diffText = "-- TOO BIG --"; } theCommit.addModification(oldPath, newPath, change, diffText, sc); } break; } return theCommit; } catch (Exception e) { throw new RuntimeException("error detailing " + id + " in " + path, e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
public void checkout(String hash) { Git git = null;/* w w w .j a v a2 s . c o m*/ try { git = Git.open(new File(path)); deleteMMBranch(git); git.checkout().setCreateBranch(true).setName("mm").setStartPoint(hash).setForce(true).call(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
public void reset() { Git git = null;/*w w w .j ava 2 s. c o m*/ try { git = Git.open(new File(path)); git.checkout().setName("master").setForce(true).call(); git.branchDelete().setBranchNames("mm").setForce(true).call(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (git != null) git.close(); } }
From source file:br.com.metricminer2.scm.GitRepository.java
License:Apache License
@Override public String blame(String file, String currentCommit, Integer line) { Git git = null;/* w w w . j a v a 2 s. com*/ try { git = Git.open(new File(path)); Iterable<RevCommit> commits = git.log().add(git.getRepository().resolve(currentCommit)).call(); ObjectId prior = commits.iterator().next().getParent(0).getId(); BlameResult blameResult = git.blame().setFilePath(file).setStartCommit(prior).setFollowFileRenames(true) .call(); return blameResult.getSourceCommit(line).getId().getName(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (git != null) git.close(); } }
From source file:br.edu.ifpb.scm.api.git.Github.java
public Git getRepository(File directory) throws ReferenceException { try {//from w w w . jav a2s . co m return Git.open(directory); } catch (IOException e) { throw new ReferenceException(e); } }
From source file:br.edu.ifpb.scm.api.loads.Loader.java
public static void main(String[] args) throws IOException, ParseException { Git repo = Git.open(DIRECTORY_PRIS); // ScmAbstractFactory factory = new ScmFactory(); // try { /* Fazendo clone de um repositrio */ // Git gitRepository = factory.createGit().clone(REMOTE_URL,DIRECTORY_PRIS); // Git repository = factory.createGithub().clone(DIRECTORY, "/Users/job/Documents/dev/testes/exemplo-jcabi/dataTeste/v1"); /*Fazendo checkout de uma reviso especfica*/ // Ref call = gitRepository.checkout().setName(HASH).call(); /*Recuperando commits a partir de um intervalo de tempo - Teste*/ // LogCommand log = gitRepository.log(); // // log.call().forEach(t -> { // lista.add(new Versao(t.getAuthorIdent().getEmailAddress(), t.getCommitterIdent().getWhen())); // }); ////ww w.j av a2s. c o m // String inicio = "01/06/2016"; // String fim = "10/06/2016"; // // DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); // // Date since = df.parse(inicio); // Date until = df.parse(fim); //// bw(since, until).forEach(System.out::println); //// bw(t->t.getData().after(since)).forEach(System.out::println); // bw(t -> t.getEmail().startsWith("j")).forEach(System.out::println); /*END*/ // DIRECTORY_JOB.delete(); /*Mostrando o tipo e quais arquivos foram alterados*/ // showDiffs(gitRepository); // // /*Mostrando que alteraes foram feitas no(s) arquivo(s)*/ showFileDiffs(repo); // }
From source file:br.gov.servicos.editor.conteudo.RepositorioGitTest.java
@SneakyThrows private void verificaSeBranchExisteLocalERemoto(File localRepo) throws GitAPIException { try (Git git = Git.open(localRepo)) { List<Ref> branchesList = git.branchList().setListMode(ALL).call(); branchesList.stream().map(Ref::getName) .map(n -> n.replaceAll(R_HEADS + "|" + R_REMOTES + "origin/", "")).forEach(System.out::println); Stream<String> branches = branchesList.stream().map(Ref::getName) .map(n -> n.replaceAll(R_HEADS + "|" + R_REMOTES + "origin/", "")); assertTrue(branches.noneMatch(n -> n.equals("foo"))); }//from ww w .ja v a 2 s . co m }
From source file:br.gov.servicos.editor.conteudo.RepositorioGitTest.java
private void garanteQueAlteracaoFoiPara(File localRepo, String branch) throws IOException { try (Git git = Git.open(localRepo)) { Ref foo = git.getRepository().getRef(branch); assertThat(foo, is(notNullValue())); RevCommit commit = new RevWalk(git.getRepository()).parseCommit(foo.getObjectId()); assertThat(commit.getAuthorIdent().getName(), is("fulano")); assertThat(commit.getAuthorIdent().getEmailAddress(), is("servicos@planejamento.gov.br")); assertThat(commit.getFullMessage(), is("Alterao de teste")); }/*from w w w .j ava2 s. c o m*/ }