List of usage examples for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder
FileRepositoryBuilder
From source file:com.cisco.step.jenkins.plugins.jenkow.JenkowWorkflowRepository.java
License:Open Source License
@Override public Repository openRepository() throws IOException { File rd = getRepositoryDir(); // TODO 7: should we cache r here? Who will be closing r? FileRepository r = new FileRepositoryBuilder().setWorkTree(rd).build(); if (!r.getObjectDatabase().exists()) { r.create();//from w ww. j a v a 2 s . c o m try { new FilePath(rd).untarFrom( JenkowWorkflowRepository.class.getResourceAsStream("/jenkow-repository-seed.tar"), FilePath.TarCompression.NONE); } catch (InterruptedException e1) { LOGGER.log(Level.WARNING, "Seeding of jenkow-repository failed", e1); } addAndCommit(r, ".", "Initial import of the existing contents"); } return r; }
From source file:com.crygier.git.rest.util.GitUtil.java
License:Apache License
public static Git getGit(File gitDirectory) { if (gitDirectory == null) return null; FileRepositoryBuilder builder = new FileRepositoryBuilder(); try {// w w w . j ava 2 s . co m Repository repository = builder.setGitDir(new File(gitDirectory, ".git")).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); return new Git(repository); } catch (IOException e) { logger.log(Level.SEVERE, "Unable to open git directory", e); return null; } }
From source file:com.diffplug.gradle.spotless.GitAttributesLineEndingPolicy.java
License:Apache License
public static GitAttributesLineEndingPolicy create(File rootFolder) { return Errors.rethrow().get(() -> { FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.findGitDir(rootFolder);/*from w w w.ja v a 2 s.c o m*/ if (builder.getGitDir() != null) { // we found a repository, so we can grab all the values we need from it Repository repo = builder.build(); AttributesNodeProvider nodeProvider = repo.createAttributesNodeProvider(); Function<AttributesNode, List<AttributesRule>> getRules = node -> node == null ? Collections.emptyList() : node.getRules(); return new GitAttributesLineEndingPolicy(repo.getConfig(), getRules.apply(nodeProvider.getInfoAttributesNode()), repo.getWorkTree(), getRules.apply(nodeProvider.getGlobalAttributesNode())); } else { // there's no repo, so it takes some work to grab the system-wide values Config systemConfig = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED); Config userConfig = SystemReader.getInstance().openUserConfig(systemConfig, FS.DETECTED); if (userConfig == null) { userConfig = new Config(); } List<AttributesRule> globalRules = Collections.emptyList(); // copy-pasted from org.eclipse.jgit.lib.CoreConfig String globalAttributesPath = userConfig.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE); // copy-pasted from org.eclipse.jgit.internal.storage.file.GlobalAttributesNode if (globalAttributesPath != null) { FS fs = FS.detect(); File attributesFile; if (globalAttributesPath.startsWith("~/")) { //$NON-NLS-1$ attributesFile = fs.resolve(fs.userHome(), globalAttributesPath.substring(2)); } else { attributesFile = fs.resolve(null, globalAttributesPath); } globalRules = parseRules(attributesFile); } return new GitAttributesLineEndingPolicy(userConfig, // no git info file Collections.emptyList(), null, globalRules); } }); }
From source file:com.gitblit.AddIndexedBranch.java
License:Apache License
public static void main(String... args) { Params params = new Params(); CmdLineParser parser = new CmdLineParser(params); try {//w w w .java 2 s.com parser.parseArgument(args); } catch (CmdLineException t) { System.err.println(t.getMessage()); parser.printUsage(System.out); return; } // create a lowercase set of excluded repositories Set<String> exclusions = new TreeSet<String>(); for (String exclude : params.exclusions) { exclusions.add(exclude.toLowerCase()); } // determine available repositories File folder = new File(params.folder); List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1, null); int modCount = 0; int skipCount = 0; for (String repo : repoList) { boolean skip = false; for (String exclusion : exclusions) { if (StringUtils.fuzzyMatch(repo, exclusion)) { skip = true; break; } } if (skip) { System.out.println("skipping " + repo); skipCount++; continue; } try { // load repository config File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED); Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); StoredConfig config = repository.getConfig(); config.load(); Set<String> indexedBranches = new LinkedHashSet<String>(); // add all local branches to index if (params.addAllLocalBranches) { List<RefModel> list = JGitUtils.getLocalBranches(repository, true, -1); for (RefModel refModel : list) { System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", refModel.getName(), repo)); indexedBranches.add(refModel.getName()); } } else { // add only one branch to index ('default' if not specified) System.out.println( MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo)); indexedBranches.add(params.branch); } String[] branches = config.getStringList("gitblit", null, "indexBranch"); if (!ArrayUtils.isEmpty(branches)) { for (String branch : branches) { indexedBranches.add(branch); } } config.setStringList("gitblit", null, "indexBranch", new ArrayList<String>(indexedBranches)); config.save(); modCount++; } catch (Exception e) { System.err.println(repo); e.printStackTrace(); } } System.out.println( MessageFormat.format("updated {0} repository configurations, skipped {1}", modCount, skipCount)); }
From source file:com.gitblit.servlet.GitServletTest.java
License:Apache License
@Test public void testPushLog() throws IOException { String name = "refchecks/ticgit.git"; File refChecks = new File(GitBlitSuite.REPOSITORIES, name); Repository repository = new FileRepositoryBuilder().setGitDir(refChecks).build(); List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository); GitBlitSuite.close(repository);// w w w.j av a 2s . c o m assertTrue("Repository has an empty push log!", pushes.size() > 0); }
From source file:com.gitblit.tests.GitBlitSuite.java
License:Apache License
private static Repository getRepository(String name) { try {// w ww. j a va 2s. com File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED); if (gitDir == null) gitDir = new File("data/git/helloworld.git"); Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); return repository; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.gitblit.tests.PushLogTest.java
License:Apache License
@Test public void testPushLog() throws IOException { String name = "~james/helloworld.git"; File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED); Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository); GitBlitSuite.close(repository);/*from w ww. j av a2 s .c om*/ }
From source file:com.gitblit.utils.JGitUtils.java
License:Apache License
/** * Clone or Fetch a repository. If the local repository does not exist, * clone is called. If the repository does exist, fetch is called. By * default the clone/fetch retrieves the remote heads, tags, and notes. * * @param repositoriesFolder//from w ww . j av a 2 s .co m * @param name * @param fromUrl * @param bare * @param credentialsProvider * @return CloneResult * @throws Exception */ public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl, boolean bare, CredentialsProvider credentialsProvider) throws Exception { CloneResult result = new CloneResult(); if (bare) { // bare repository, ensure .git suffix if (!name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) { name += Constants.DOT_GIT_EXT; } } else { // normal repository, strip .git suffix if (name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) { name = name.substring(0, name.indexOf(Constants.DOT_GIT_EXT)); } } result.name = name; File folder = new File(repositoriesFolder, name); if (folder.exists()) { File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED); Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); result.fetchResult = fetchRepository(credentialsProvider, repository); repository.close(); } else { CloneCommand clone = new CloneCommand(); clone.setBare(bare); clone.setCloneAllBranches(true); clone.setURI(fromUrl); clone.setDirectory(folder); if (credentialsProvider != null) { clone.setCredentialsProvider(credentialsProvider); } Repository repository = clone.call().getRepository(); // Now we have to fetch because CloneCommand doesn't fetch // refs/notes nor does it allow manual RefSpec. result.createdRepository = true; result.fetchResult = fetchRepository(credentialsProvider, repository); repository.close(); } return result; }
From source file:com.github.checkstyle.github.NotesBuilder.java
License:Open Source License
/** * Returns a list of commits between two references. * @param repoPath path to local git repository. * @param startRef start reference./*www. j a v a2 s. c o m*/ * @param endRef end reference. * @return a list of commits. * @throws IOException if I/O error occurs. * @throws GitAPIException if an error occurs when accessing Git API. */ private static Set<RevCommit> getCommitsBetweenReferences(String repoPath, String startRef, String endRef) throws IOException, GitAPIException { final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Path path = Paths.get(repoPath); final Repository repo = builder.findGitDir(path.toFile()).readEnvironment().build(); final ObjectId startCommit = getActualRefObjectId(repo, startRef); Verify.verifyNotNull(startCommit, "Start reference \"" + startRef + "\" is invalid!"); final ObjectId endCommit = getActualRefObjectId(repo, endRef); final Iterable<RevCommit> commits = new Git(repo).log().addRange(startCommit, endCommit).call(); return Sets.newLinkedHashSet(commits); }
From source file:com.github.checkstyle.publishers.XdocPublisher.java
License:Open Source License
/** * Publish release notes./*from ww w . j a va 2 s. c o m*/ * @throws IOException if problem with access to files appears. * @throws GitAPIException for problems with jgit. */ public void publish() throws IOException, GitAPIException { changeLocalRepoXdoc(); final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final File localRepo = new File(localRepoPath); final Repository repo = builder.findGitDir(localRepo).readEnvironment().build(); final Git git = new Git(repo); git.add().addFilepattern(PATH_TO_XDOC_IN_REPO).call(); git.commit().setMessage(String.format(Locale.ENGLISH, COMMIT_MESSAGE_TEMPLATE, releaseNumber)).call(); if (doPush) { final CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(authToken, ""); git.push().setCredentialsProvider(credentialsProvider).call(); } }