Java Code Examples for org.eclipse.jgit.lib.Repository#getBranch()
The following examples show how to use
org.eclipse.jgit.lib.Repository#getBranch() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitTool.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 7 votes |
public GitTool() { File gitWorkDir = new File("."); try { Git git = Git.open(gitWorkDir); Iterable<RevCommit> commits = git.log().all().call(); Repository repo = git.getRepository(); branch = repo.getBranch(); RevCommit latestCommit = commits.iterator().next(); name = latestCommit.getName(); message = latestCommit.getFullMessage(); } catch (Throwable e) { name = ""; message = ""; branch = ""; } }
Example 2
Source File: GitFileDecorator.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private void addGitLinks(HttpServletRequest request, URI location, JSONObject representation) throws URISyntaxException, JSONException, CoreException, IOException { Repository db = null; try { db = repositoryForPath(request, new Path(location.getPath())); if (db != null) { URI cloneLocation = BaseToCloneConverter.getCloneLocation(location, BaseToCloneConverter.FILE); String branch = db.getBranch(); Remote defaultRemote = new Remote(cloneLocation, db, Constants.DEFAULT_REMOTE_NAME); RemoteBranch defaultRemoteBranch = new RemoteBranch(cloneLocation, db, defaultRemote, branch); addGitLinks(request, location, representation, cloneLocation, db, defaultRemoteBranch, branch); } } finally { if (db != null) { db.close(); } } }
Example 3
Source File: GitUtils.java From gitPic with MIT License | 5 votes |
/** * 获取当前分支 * * @param rep * @return */ public static String getBranch(Repository rep) { try { return rep.getBranch(); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); throw new TipException("获取Branch异常"); } }
Example 4
Source File: MergeConfig.java From onedev with MIT License | 5 votes |
/** * Get merge configuration for the current branch of the repository * * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. * @return merge configuration for the current branch of the repository */ public static MergeConfig getConfigForCurrentBranch(Repository repo) { try { String branch = repo.getBranch(); if (branch != null) return repo.getConfig().get(getParser(branch)); } catch (IOException e) { // ignore } // use defaults if branch can't be determined return new MergeConfig(); }
Example 5
Source File: AppraiseUiPlugin.java From git-appraise-eclipse with Eclipse Public License 1.0 | 5 votes |
/** * Returns the current Git branch, which in the detached head state (should * be true in the review workflow) will be the commit id. */ public String getCurrentCommit() { ITask activeTask = TasksUi.getTaskActivityManager().getActiveTask(); TaskRepository taskRepository = TasksUi.getRepositoryManager().getRepository( AppraiseConnectorPlugin.CONNECTOR_KIND, activeTask.getRepositoryUrl()); Repository repo = AppraisePluginUtils.getGitRepoForRepository(taskRepository); try { return repo.getBranch(); } catch (IOException e) { AppraiseUiPlugin.logError("Failed to retrive git branch", e); return null; } }
Example 6
Source File: GitContentRepositoryHelper.java From studio with GNU General Public License v3.0 | 5 votes |
private void makeRepoOrphan(Repository repository, String site) throws IOException, GitAPIException, ServiceLayerException, UserNotFoundException { logger.debug("Make repository orphan fir site " + site); String sandboxBranchName = repository.getBranch(); if (StringUtils.isEmpty(sandboxBranchName)) { sandboxBranchName = studioConfiguration.getProperty(REPO_SANDBOX_BRANCH); } String sandboxBranchOrphanName = sandboxBranchName + "_orphan"; logger.debug("Shallow clone is not implemented in JGit. Instead we are creating new orphan branch after " + "cloning and renaming it to sandbox branch to replace fully cloned branch"); try (Git git = new Git(repository)) { logger.debug("Create temporary orphan branch " + sandboxBranchOrphanName); git.checkout() .setName(sandboxBranchOrphanName) .setStartPoint(sandboxBranchName) .setOrphan(true) .call(); // Reset everything to simulate first commit as created empty repo logger.debug("Soft reset to commit empty repo"); git.reset().call(); logger.debug("Commit empty repo, because we need to have HEAD to delete old and rename new branch"); CommitCommand commitCommand = git.commit() .setMessage(getCommitMessage(REPO_CREATE_AS_ORPHAN_COMMIT_MESSAGE)); String username = securityService.getCurrentUser(); if (StringUtils.isNotEmpty(username)) { commitCommand = commitCommand.setAuthor(getAuthorIdent(username)); } commitCommand.call(); logger.debug("Delete cloned branch " + sandboxBranchName); git.branchDelete().setBranchNames(sandboxBranchName).setForce(true).call(); logger.debug("Rename temporary orphan branch to sandbox branch"); git.branchRename().setNewName(sandboxBranchName).setOldName(sandboxBranchOrphanName).call(); } }
Example 7
Source File: ParallelStats.java From uncc2014watsonsim with GNU General Public License v2.0 | 4 votes |
/** Send Statistics to the server */ private void report(int[] correct) { // At worst, give an empty branch and commit String branch = "", commit = ""; if (System.getenv("TRAVIS_BRANCH") != null) { // Use CI information if possible. branch = System.getenv("TRAVIS_BRANCH"); commit = System.getenv("TRAVIS_COMMIT"); } else { // Otherwise take a stab at it ourselves. try { Repository repo = new FileRepositoryBuilder() .readEnvironment() .findGitDir() .build(); commit = repo .resolve("HEAD") .abbreviate(10) .name(); if (commit == null) { commit = ""; log.warn("Problem finding git repository.\n" + "Resulting stats will be missing information."); } branch = repo.getBranch(); } catch (IOException ex) { // Well at least we tried. } } // Generate report List<NameValuePair> response = Form.form() .add("run[branch]", branch) .add("run[commit_hash]", commit.substring(0, 10)) .add("run[dataset]", dataset) .add("run[top]", String.valueOf(correct[0])) .add("run[top3]", String.valueOf(correct[0] + correct[1] + correct[2])) .add("run[available]", String.valueOf(available)) .add("run[rank]", String.valueOf(total_inverse_rank)) .add("run[total_questions]", String.valueOf(questionsource.size())) .add("run[total_answers]", String.valueOf(total_answers)) .add("run[confidence_histogram]", StringUtils.join(new int[100], " ")) .add("run[confidence_correct_histogram]", StringUtils.join(new int[100], " ")) .add("run[runtime]", String.valueOf(runtime)) .build(); try { Request.Post("http://watsonsim.herokuapp.com/runs.json").bodyForm(response).execute(); } catch (IOException e) { log.warn("Error uploading stats. Ignoring. " + "Details follow.", e); } log.info(correct[0] + " of " + questionsource.size() + " correct"); log.info(available + " of " + questionsource.size() + " could have been"); log.info("Mean Inverse Rank " + total_inverse_rank); }
Example 8
Source File: SvnTestServer.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
private SvnTestServer(@NotNull Repository repository, @Nullable String branch, @NotNull String prefix, boolean safeBranch, @Nullable UserDBConfig userDBConfig, @Nullable Function<Path, RepositoryMappingConfig> mappingConfigCreator, boolean anonymousRead, @NotNull LfsMode lfsMode, @NotNull SharedConfig... shared) throws Exception { SVNFileUtil.setSleepForTimestamp(false); this.repository = repository; this.safeBranch = safeBranch; tempDirectory = TestHelper.createTempDir("git-as-svn"); final String srcBranch = branch == null ? repository.getBranch() : branch; if (safeBranch) { cleanupBranches(repository); testBranch = TEST_BRANCH_PREFIX + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 8); new Git(repository) .branchCreate() .setName(testBranch) .setStartPoint(srcBranch) .call(); } else { testBranch = srcBranch; } this.prefix = prefix + "/" + testBranch; final Config config = new Config(BIND_HOST, 0); config.setCompressionLevel(SVNDeltaCompression.None); config.setCacheConfig(new MemoryCacheConfig()); switch (lfsMode) { case Local: { config.getShared().add(new WebServerConfig(0)); config.getShared().add(new LocalLfsConfig(tempDirectory.resolve("lfs").toString(), false)); break; } case Memory: { config.getShared().add(context -> context.add(LfsStorageFactory.class, localContext -> new LfsMemoryStorage())); break; } } if (mappingConfigCreator != null) { config.setRepositoryMapping(mappingConfigCreator.apply(tempDirectory)); } else { config.setRepositoryMapping(new TestRepositoryConfig(repository, testBranch, prefix, anonymousRead)); } if (userDBConfig != null) { config.setUserDB(userDBConfig); } else { config.setUserDB(new LocalUserDBConfig(new LocalUserDBConfig.UserEntry[]{ new LocalUserDBConfig.UserEntry(USER_NAME, REAL_NAME, EMAIL, PASSWORD), new LocalUserDBConfig.UserEntry(USER_NAME_NO_MAIL, REAL_NAME, null, PASSWORD), })); } Collections.addAll(config.getShared(), shared); server = new SvnServer(tempDirectory, config); server.start(); log.info("Temporary server started (url: {}, path: {}, branch: {} as {})", getUrl(), repository.getDirectory(), srcBranch, testBranch); log.info("Temporary directory: {}", tempDirectory); }
Example 9
Source File: RepositoryHelper.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 3 votes |
public static void createTestBranch(Repository repository, String branch, BranchAction action) throws IOException, GitAPIException { Git git = new Git(repository); String origin = repository.getBranch(); git.checkout().setName(branch).setCreateBranch(true).call(); action.apply(git, branch); git.checkout().setName(origin).call(); }