List of usage examples for org.eclipse.jgit.lib Constants R_HEADS
String R_HEADS
To view the source code for org.eclipse.jgit.lib Constants R_HEADS.
Click Source Link
From source file:com.rimerosolutions.ant.git.tasks.FetchTask.java
License:Apache License
@Override public void doExecute() { try {/*from w ww .j a v a 2 s. c om*/ StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec("+" + Constants.R_HEADS + "*:" + Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*")); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REMOTE, Constants.DEFAULT_REMOTE_NAME); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + Constants.MASTER); remoteConfig.update(config); config.save(); } List<RefSpec> specs = new ArrayList<RefSpec>(3); specs.add(new RefSpec( "+" + Constants.R_HEADS + "*:" + Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*")); specs.add(new RefSpec("+" + Constants.R_NOTES + "*:" + Constants.R_NOTES + "*")); specs.add(new RefSpec("+" + Constants.R_TAGS + "*:" + Constants.R_TAGS + "*")); FetchCommand fetchCommand = git.fetch().setDryRun(dryRun).setThin(thinPack).setRemote(getUri()) .setRefSpecs(specs).setRemoveDeletedRefs(removeDeletedRefs); setupCredentials(fetchCommand); if (getProgressMonitor() != null) { fetchCommand.setProgressMonitor(getProgressMonitor()); } FetchResult fetchResult = fetchCommand.call(); GitTaskUtils.validateTrackingRefUpdates(FETCH_FAILED_MESSAGE, fetchResult.getTrackingRefUpdates()); log(fetchResult.getMessages()); } catch (URISyntaxException e) { throw new GitBuildException("Invalid URI syntax: " + e.getMessage(), e); } catch (IOException e) { throw new GitBuildException("Could not save or get repository configuration: " + e.getMessage(), e); } catch (InvalidRemoteException e) { throw new GitBuildException("Invalid remote URI: " + e.getMessage(), e); } catch (TransportException e) { throw new GitBuildException("Communication error: " + e.getMessage(), e); } catch (GitAPIException e) { throw new GitBuildException("Unexpected exception: " + e.getMessage(), e); } }
From source file:com.rimerosolutions.ant.git.tasks.PushTask.java
License:Apache License
@Override protected void doExecute() { try {// w w w.ja v a2 s . com StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.addPushRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.update(config); config.save(); } String currentBranch = git.getRepository().getBranch(); List<RefSpec> specs = Arrays.asList(new RefSpec(currentBranch + ":" + currentBranch)); if (deleteRemoteBranch != null) { specs = Arrays.asList(new RefSpec(":" + Constants.R_HEADS + deleteRemoteBranch)); } PushCommand pushCommand = git.push().setPushAll().setRefSpecs(specs).setDryRun(false); if (getUri() != null) { pushCommand.setRemote(getUri()); } setupCredentials(pushCommand); if (includeTags) { pushCommand.setPushTags(); } if (getProgressMonitor() != null) { pushCommand.setProgressMonitor(getProgressMonitor()); } Iterable<PushResult> pushResults = pushCommand.setForce(true).call(); for (PushResult pushResult : pushResults) { log(pushResult.getMessages()); GitTaskUtils.validateRemoteRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getRemoteUpdates()); GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates()); } } catch (Exception e) { if (pushFailedProperty != null) { getProject().setProperty(pushFailedProperty, e.getMessage()); } throw new GitBuildException(PUSH_FAILED_MESSAGE, e); } }
From source file:com.surevine.gateway.scm.git.jgit.BundleWriter.java
License:Eclipse Distribution License
/** * Include a single ref (a name/object pair) in the bundle. * <p>/* www.ja v a2s . c o m*/ * This is a utility function for: * <code>include(r.getName(), r.getObjectId())</code>. * * @param r * the ref to include. */ public void include(final Ref r) { include(r.getName(), r.getObjectId()); if (r.getPeeledObjectId() != null) tagTargets.add(r.getPeeledObjectId()); else if (r.getObjectId() != null && r.getName().startsWith(Constants.R_HEADS)) tagTargets.add(r.getObjectId()); }
From source file:com.tasktop.c2c.server.internal.profile.service.template.GitServiceCloner.java
License:Open Source License
private void copyRepo(ScmRepository scmRepo, CloneContext context) throws IOException, JGitInternalException, GitAPIException { File workDirectory = null;/*from w w w . j a v a2 s. com*/ try { Project templateProject = context.getTemplateService().getProjectServiceProfile().getProject(); String cloneUrl = jgitProvider.computeRepositoryUrl(templateProject.getIdentifier(), scmRepo.getName()); AuthUtils.assumeSystemIdentity(templateProject.getIdentifier()); tenancyManager.establishTenancyContext(context.getTemplateService()); workDirectory = createTempDirectory(); Git git = Git.cloneRepository().setDirectory(workDirectory) .setBranch(Constants.R_HEADS + Constants.MASTER).setURI(cloneUrl).call(); AuthUtils.assumeSystemIdentity( context.getTargetService().getProjectServiceProfile().getProject().getIdentifier()); tenancyManager.establishTenancyContext(context.getTargetService()); FileUtils.deleteDirectory(git.getRepository().getDirectory()); git = Git.init().setDirectory(git.getRepository().getDirectory().getParentFile()).call(); maybeRewriteRepo(workDirectory, context); String pushUrl = jgitProvider.computeRepositoryUrl( context.getTargetService().getProjectServiceProfile().getProject().getIdentifier(), scmRepo.getName()); // FIXME: User's locale is not defined here String commitMessage = messageSource.getMessage("project.template.git.commitMessage", new Object[] { templateProject.getName() }, null); git.add().addFilepattern(".").call(); git.commit().setCommitter(committerName, committerEmail).setMessage(commitMessage).call(); git.getRepository().getConfig().setString("remote", "target", "url", pushUrl); git.push().setRemote("target").setPushAll().call(); } finally { if (workDirectory != null) { FileUtils.deleteDirectory(workDirectory); } } }
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
private void visitAllCommitsAfter(Repository repository, Date maxDate, CommitVisitor visitor, Set<ObjectId> visited) { try {/*w w w . ja v a2 s . c o m*/ for (Entry<String, Ref> entry : repository.getAllRefs().entrySet()) { if (entry.getValue().getName().startsWith(Constants.R_HEADS)) { RevWalk revWal = new RevWalk(repository); revWal.markStart(revWal.parseCommit(entry.getValue().getObjectId())); int commitsPastDate = 0; for (RevCommit revCommit : revWal) { if (revCommit.getCommitterIdent().getWhen().getTime() < maxDate.getTime()) { commitsPastDate++; } else { commitsPastDate = 0; if (visited.add(revCommit)) { visitor.visit(revCommit); } else { break; } } if (commitsPastDate > 5) { break; } } revWal.dispose(); } } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
private List<Ref> getRefsToAdd(Repository repository) { List<Ref> result = new ArrayList<Ref>(); Ref master = null;/*from w ww . j a v a2s. c o m*/ for (Entry<String, Ref> entry : repository.getAllRefs().entrySet()) { if (entry.getValue().getName().equals(Constants.R_HEADS + Constants.MASTER)) { master = entry.getValue(); } else if (entry.getValue().getName().startsWith(Constants.R_HEADS)) { result.add(entry.getValue()); } } if (master != null) { result.add(0, master); } return result; }
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
/** * @param repo/* ww w . j a va2s . co m*/ * @param git */ private void setBranchesAndTags(ScmRepository repo, Git git) { repo.setBranches(new ArrayList<String>()); try { for (Ref ref : git.branchList().call()) { String refName = ref.getName(); if (refName.startsWith(Constants.R_HEADS)) { refName = refName.substring(Constants.R_HEADS.length()); } repo.getBranches().add(refName); } } catch (GitAPIException e) { throw new JGitInternalException(e.getMessage(), e); } RevWalk revWalk = new RevWalk(git.getRepository()); Map<String, Ref> refList; repo.setTags(new ArrayList<String>()); try { refList = git.getRepository().getRefDatabase().getRefs(Constants.R_TAGS); for (Ref ref : refList.values()) { repo.getTags().add(ref.getName().substring(Constants.R_TAGS.length())); } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } finally { revWalk.release(); } Collections.sort(repo.getTags()); }
From source file:de.br0tbox.gitfx.ui.controllers.SingleProjectController.java
License:Apache License
private void addBranchesToView() { treeView.showRootProperty().set(false); branchesItem.getChildren().clear();/*from w w w .ja va2 s. c o m*/ remotesItem.getChildren().clear(); tagsItem.getChildren().clear(); final List<String> localList = projectModel.getLocalBranchesProperty(); final List<String> remoteList = projectModel.getRemoteBranchesProperty(); final List<String> tagsList = projectModel.getTagsProperty(); for (String local : localList) { if (local.startsWith(Constants.R_HEADS)) { local = local.substring(Constants.R_HEADS.length(), local.length()); } branchesItem.getChildren().add(new TreeItem(local)); } for (String remote : remoteList) { if (remote.startsWith(Constants.R_REMOTES)) { remote = remote.substring(Constants.R_REMOTES.length(), remote.length()); } remotesItem.getChildren().add(new TreeItem(remote)); } for (String tag : tagsList) { if (tag.startsWith(Constants.R_TAGS)) { tag = tag.substring(Constants.R_TAGS.length(), tag.length()); } tagsItem.getChildren().add(new TreeItem(tag)); } branchesItem.expandedProperty().set(true); remotesItem.expandedProperty().set(true); tagsItem.expandedProperty().set(true); }
From source file:de.br0tbox.gitfx.ui.history.JavaFxPlotRenderer.java
License:Apache License
@Override protected int drawLabel(int x, int y, Ref ref) { String refName = ref.getName(); if (refName.contains(Constants.R_HEADS)) { refName = refName.substring(Constants.R_HEADS.length(), refName.length()); }//w ww . j a va 2 s. com if (refName.contains(Constants.R_REMOTES)) { refName = refName.substring(Constants.R_REMOTES.length(), refName.length()); } if (refName.contains(Constants.R_TAGS)) { refName = refName.substring(Constants.R_TAGS.length(), refName.length()); } final Text text = new Text(refName); text.setX(x); text.setY(y * 1.5); text.setFill(Color.RED); final double fontSize = text.getFont().getSize(); final int width = (int) Math.floor(fontSize * refName.trim().length() / 2); // final Rectangle rectangle = RectangleBuilder.create().x(x).y(y / // 2).width(width).height(fontSize + 3).fill(Color.RED).build(); // currentShape.getChildren().add(rectangle); currentShape.getChildren().add(text); return (int) Math.floor(10 + width); }
From source file:jbyoshi.gitupdate.processor.Fetch.java
License:Apache License
@Override public void process(Repository repo, Git git, String remote, String fullRemote, Report report) throws GitAPIException, IOException { FetchResult result = git.fetch().setRemoveDeletedRefs(true).setCredentialsProvider(Prompts.INSTANCE) .setRemote(remote).call();/*w w w . ja v a 2s . c o m*/ for (TrackingRefUpdate update : result.getTrackingRefUpdates()) { if (update.getRemoteName().equals(Constants.R_HEADS + Constants.HEAD)) { continue; } StringBuilder text = new StringBuilder(Utils.getShortBranch(update.getRemoteName())).append(": "); String oldId = update.getOldObjectId().name(); if (update.getOldObjectId().equals(ObjectId.zeroId())) { oldId = "new branch"; } String newId = update.getNewObjectId().name(); if (update.getNewObjectId().equals(ObjectId.zeroId())) { newId = "deleted"; for (String branch : Utils.getLocalBranches(repo).keySet()) { if (update.getLocalName() .equals(new BranchConfig(repo.getConfig(), branch).getRemoteTrackingBranch())) { repo.getConfig().unset("branches", branch, "remote"); repo.getConfig().save(); } } } text.append(oldId).append(" -> ").append(newId); report.newChild(text.toString()).modified(); } }