List of usage examples for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder
FileRepositoryBuilder
From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario13GitflowWithNonQualifierAndPartialNameTest.java
License:Apache License
/** * Prepare common variables to access the git repository. * /* ww w .java2s . c om*/ * @throws IOException if a disk error occurred */ @Before public void init() throws IOException { repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build(); git = new Git(repository); versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true) .setQualifierBranchingPolicies(BranchingPolicy.ignoreBranchName("master"), BranchingPolicy.fixedBranchName("develop"), new BranchingPolicy("release/(.*)", Collections.singletonList(BranchNameTransformations.IGNORE.name())), new BranchingPolicy("feature/(.*)", Arrays.asList(BranchNameTransformations.REMOVE_UNEXPECTED_CHARS.name(), BranchNameTransformations.LOWERCASE_EN.name()))) .setUseDefaultBranchingPolicy(false); // reset the head to master unchecked(() -> git.checkout().setName("master").call()); }
From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario5WithMasterAndIntBranchesNonQualifiedTest.java
License:Apache License
/** * Prepare common variables to access the git repository. * /*from ww w . j a va2 s . c o m*/ * @throws IOException if a disk error occurred */ @Before public void init() throws IOException { repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build(); git = new Git(repository); versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true) .setNonQualifierBranches("master,int"); // reset the head to master unchecked(() -> git.checkout().setName("master").call()); }
From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario5WithNoDefaultQualiferNoNonQualiferTest.java
License:Apache License
/** * Prepare common variables to access the git repository. * /*from ww w . j a va 2 s .c om*/ * @throws IOException if a disk error occurred */ @Before public void init() throws IOException { repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build(); git = new Git(repository); versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true) .setUseDefaultBranchingPolicy(false).setNonQualifierBranches(""); // reset the head to master unchecked(() -> git.checkout().setName("master").call()); }
From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario5WithNoDefaultQualiferTest.java
License:Apache License
/** * Prepare common variables to access the git repository. * /*from w w w. j av a 2 s.com*/ * @throws IOException if a disk error occurred */ @Before public void init() throws IOException { repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build(); git = new Git(repository); versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true) .setUseDefaultBranchingPolicy(false); // reset the head to master unchecked(() -> git.checkout().setName("master").call()); }
From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario6WithSpecificFindTagPatternTest.java
License:Apache License
/** * Prepare common variables to access the git repository. * //w w w .j ava2 s . co m * @throws IOException if a disk error occurred */ @Before public void init() throws IOException { repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build(); git = new Git(repository); versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true) .setFindTagVersionPattern("a([0-9]\\.[0-9])"); // reset the head to master unchecked(() -> git.checkout().setName("master").call()); }
From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario9WithEmptyRepositoryTest.java
License:Apache License
/** * Prepare common variables to access the git repository. * /* w w w . j a v a2s. com*/ * @throws IOException if a disk error occurred */ @Before public void init() throws IOException { repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build(); git = new Git(repository); versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true); }
From source file:GitBackend.GitAPI.java
License:Apache License
private Git openOrCreate(File localDirectory, String remoteRepo) throws IOException, GitAPIException { Git git = null;//from www . j a v a 2 s .c o m FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder(); repositoryBuilder.addCeilingDirectory(localDirectory); repositoryBuilder.findGitDir(localDirectory); if (repositoryBuilder.getGitDir() == null) { // git = Git.init().setDirectory( gitDirectory.getParentFile() ).call(); try { Git.cloneRepository().setURI(remoteRepo).setDirectory(localDirectory).call(); } catch (GitAPIException e) { e.printStackTrace(); } } else { git = new Git(repositoryBuilder.build()); } return git; }
From source file:gitrunner.GitRunner.java
/** * @param args the command line arguments *//* w w w . ja v a2s . c o m*/ public static void main(String[] args) { try { // Run git status for fun using Process Process p = Runtime.getRuntime().exec("git status"); BufferedReader reader; BufferedReader error_reader; reader = new BufferedReader(new InputStreamReader(p.getInputStream())); error_reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); String cmd_output = null; while ((cmd_output = reader.readLine()) != null) { System.out.println(cmd_output); } while ((cmd_output = error_reader.readLine()) != null) { System.out.println("Error: " + cmd_output); } // Now use Jgit to get "git status" System.out.println("\n\n ===== Using Jgit ====="); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.readEnvironment().findGitDir().build(); if (repo == null) { System.err.println("No repo"); } else { System.out.println("Got repo"); } Git git = new Git(repo); Status status = null; try { status = git.status().call(); } catch (GitAPIException ex) { Logger.getLogger(GitRunner.class.getName()).log(Level.SEVERE, null, ex); System.exit(-1); } catch (NoWorkTreeException ex) { Logger.getLogger(GitRunner.class.getName()).log(Level.SEVERE, null, ex); System.exit(-1); } Set<String> result = new HashSet<>(); System.out.println("Untracked = " + status.getUntracked()); result.addAll(status.getModified()); result.addAll(status.getAdded()); result.addAll(status.getUntracked()); System.out.println(result.toString()); } catch (IOException ex) { Logger.getLogger(GitRunner.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:hd3gtv.configuration.GitInfo.java
License:Open Source License
public GitInfo(File repository_file) throws IOException { if (repository_file == null) { throw new NullPointerException("\"repository_file\" can't to be null"); }// w w w . j a va 2 s . co m if (repository_file.exists() == false) { throw new IOException("Can't found \"" + repository_file + "\""); } if (repository_file.isDirectory() == false) { throw new IOException("\"" + repository_file + "\" is not a directory"); } try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(repository_file).readEnvironment().findGitDir().build(); if (repository.getBranch() == null) { throw new FileNotFoundException("Can't found branch in \"" + repository_file + "\""); } branch = repository.getBranch(); commit = repository.getRef(Constants.HEAD).getObjectId().abbreviate(8).name(); } catch (Exception e) { throw new IOException("Can't load git repository \"" + repository_file + "\""); } }
From source file:info.debatty.jinu.Case.java
License:Open Source License
private void commitToGit(final String time_tag) { try {//from w w w . j av a 2s . c o m Repository repo = new FileRepositoryBuilder().findGitDir().build(); Git git = new Git(repo); git.add().addFilepattern(".").call(); git.commit().setAll(true).setMessage("Test case " + time_tag).call(); git.tag().setName("T" + time_tag).call(); } catch (Exception ex) { System.err.println("Could not commit GIT repo"); System.err.println(ex.getMessage()); } }