List of usage examples for org.eclipse.jgit.lib Constants R_REMOTES
String R_REMOTES
To view the source code for org.eclipse.jgit.lib Constants R_REMOTES.
Click Source Link
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private void setWalkStartPoints(RevWalk walk, Repository repo, AnyObjectId headId) throws IOException { markStartAllRefs(repo, walk, Constants.R_HEADS); markStartAllRefs(repo, walk, Constants.R_REMOTES); markStartAllRefs(repo, walk, Constants.R_TAGS); markStartAdditionalRefs(repo, walk); markUninteresting(repo, walk, Constants.R_NOTES); walk.markStart(walk.parseCommit(headId)); }
From source file:org.flowerplatform.web.git.operation.CheckoutOperation.java
License:Open Source License
public boolean execute() { ProgressMonitor monitor = ProgressMonitor .create(GitPlugin.getInstance().getMessage("git.checkout.monitor.title"), channel); try {// ww w. j a v a2 s . c o m monitor.beginTask( GitPlugin.getInstance().getMessage("git.checkout.monitor.message", new Object[] { name }), 4); monitor.setTaskName("Getting remote branch..."); Git git = new Git(repository); Ref ref; if (node instanceof Ref) { ref = (Ref) node; } else { // get remote branch String dst = Constants.R_REMOTES + remote.getName(); String remoteRefName = dst + "/" + upstreamBranch.getShortName(); ref = repository.getRef(remoteRefName); if (ref == null) { // doesn't exist, fetch it RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(upstreamBranch.getName(), remoteRefName); git.fetch().setRemote(new URIish(remote.getUri()).toPrivateString()).setRefSpecs(refSpec) .call(); ref = repository.getRef(remoteRefName); } } monitor.worked(1); monitor.setTaskName("Creating local branch..."); // create local branch git.branchCreate().setName(name).setStartPoint(ref.getName()) .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call(); if (!(node instanceof Ref)) { // save upstream configuration StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_MERGE, upstreamBranch.getName()); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REMOTE, remote.getName()); if (rebase) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REBASE, true); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REBASE); } config.save(); } monitor.worked(1); monitor.setTaskName("Creating working directory"); // create working directory for local branch File mainRepoFile = repository.getDirectory().getParentFile(); File wdirFile = new File(mainRepoFile.getParentFile(), GitUtils.WORKING_DIRECTORY_PREFIX + name); if (wdirFile.exists()) { GitPlugin.getInstance().getUtils().delete(wdirFile); } GitPlugin.getInstance().getUtils().run_git_workdir_cmd(mainRepoFile.getAbsolutePath(), wdirFile.getAbsolutePath()); monitor.worked(1); monitor.setTaskName("Checkout branch"); // checkout local branch Repository wdirRepo = GitPlugin.getInstance().getUtils().getRepository(wdirFile); git = new Git(wdirRepo); CheckoutCommand cc = git.checkout().setName(name).setForce(true); cc.call(); // show checkout result if (cc.getResult().getStatus() == CheckoutResult.Status.CONFLICTS) channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.checkout.checkoutConflicts.title"), GitPlugin.getInstance().getMessage("git.checkout.checkoutConflicts.message"), cc.getResult().getConflictList().toString(), DisplaySimpleMessageClientCommand.ICON_INFORMATION)); else if (cc.getResult().getStatus() == CheckoutResult.Status.NONDELETED) { // double-check if the files are still there boolean show = false; List<String> pathList = cc.getResult().getUndeletedList(); for (String path1 : pathList) { if (new File(wdirRepo.getWorkTree(), path1).exists()) { show = true; break; } } if (show) { channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.checkout.nonDeletedFiles.title"), GitPlugin.getInstance().getMessage("git.checkout.nonDeletedFiles.message", Repository.shortenRefName(name)), cc.getResult().getUndeletedList().toString(), DisplaySimpleMessageClientCommand.ICON_ERROR)); } } else if (cc.getResult().getStatus() == CheckoutResult.Status.OK) { if (ObjectId.isId(wdirRepo.getFullBranch())) channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.checkout.detachedHead.title"), GitPlugin.getInstance().getMessage("git.checkout.detachedHead.message"), DisplaySimpleMessageClientCommand.ICON_ERROR)); } monitor.worked(1); return true; } catch (Exception e) { channel.appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } finally { monitor.done(); } }
From source file:org.gitective.tests.RepositoryUtilsTest.java
License:Open Source License
/** * Test one origin change/*from w ww . j a v a2 s . c o m*/ * * * @throws Exception */ @Test public void oneOriginChange() throws Exception { RevCommit commit1 = add("test.txt", "content"); File repo2 = initRepo(); RevCommit commit2 = add(repo2, "test2.txt", "content2.txt"); Repository repo = new FileRepository(testRepo); RefUpdate originMaster = repo .updateRef(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER); originMaster.setNewObjectId(commit1); originMaster.forceUpdate(); RemoteConfig config = new RemoteConfig(repo.getConfig(), Constants.DEFAULT_REMOTE_NAME); config.addURI(new URIish(repo2.toURI().toString())); config.update(repo.getConfig()); Collection<RefDiff> diffs = RepositoryUtils.diffOriginRefs(repo); assertNotNull(diffs); assertFalse(diffs.isEmpty()); assertNotNull(diffs.iterator().next().getLocal()); assertNotNull(diffs.iterator().next().getRemote()); assertEquals(commit1, diffs.iterator().next().getLocal().getObjectId()); assertEquals(commit2, diffs.iterator().next().getRemote().getObjectId()); }
From source file:org.jboss.forge.git.Clone.java
License:Eclipse Distribution License
private void saveRemote(final URIish uri) throws URISyntaxException, IOException { final FileBasedConfig dstcfg = db.getConfig(); final RemoteConfig rc = new RemoteConfig(dstcfg, remoteName); rc.addURI(uri);//from ww w .ja va 2 s. c o m rc.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + remoteName + "/*")); rc.update(dstcfg); dstcfg.save(); }
From source file:org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportProjectOperation.java
License:Open Source License
/** * Fetches and creates the branch with the given name from the given remote. * @param gitRef/*from w w w . j av a2s . c o m*/ * @param project * @param repository * @param monitor * @throws CoreException * @throws InvocationTargetException * @throws IOException */ private void fetchBranch(String gitRef, RemoteConfig remote, Repository repository, IProgressMonitor monitor) throws CoreException, InvocationTargetException, IOException { if (remote == null) { throw new CoreException(StatusFactory.errorStatus(OpenShiftUIActivator.PLUGIN_ID, NLS.bind( "Could not fetch determine the remote for the repo at {0} that we should fetch branch {1} from.", repository.getDirectory(), gitRef))); } EGitUtils.fetch(remote, Arrays.asList(new RefSpec( Constants.R_HEADS + gitRef + ":" + Constants.R_REMOTES + remote.getName() + "/" + gitRef)), repository, monitor); RevCommit commit = EGitUtils.getLatestCommit(gitRef, remote.getName(), repository); EGitUtils.createBranch(gitRef, commit, repository, monitor); }
From source file:org.jboss.tools.tycho.sitegenerator.GenerateRepositoryFacadeMojo.java
License:Open Source License
private ModelNode createRevisionObject() throws IOException, FileNotFoundException { ModelNode res = new ModelNode(); File repoRoot = findRepoRoot(this.project.getBasedir()); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository gitRepo = builder.setGitDir(new File(repoRoot, ".git")).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build();/*w ww .j a v a 2 s . c om*/ Ref head = gitRepo.getRef(Constants.HEAD); res.get("HEAD").set(head.getObjectId().getName()); if (head.getTarget() != null && head.getTarget().getName() != null) { res.get("currentBranch").set(head.getTarget().getName()); } ModelNode knownReferences = new ModelNode(); for (Entry<String, Ref> entry : gitRepo.getAllRefs().entrySet()) { if (entry.getKey().startsWith(Constants.R_REMOTES) && entry.getValue().getObjectId().getName().equals(head.getObjectId().getName())) { ModelNode reference = new ModelNode(); String remoteName = entry.getKey().substring(Constants.R_REMOTES.length()); remoteName = remoteName.substring(0, remoteName.indexOf('/')); String remoteUrl = gitRepo.getConfig().getString("remote", remoteName, "url"); String branchName = entry.getKey() .substring(Constants.R_REMOTES.length() + 1 + remoteName.length()); reference.get("name").set(remoteName); reference.get("url").set(remoteUrl); reference.get("ref").set(branchName); knownReferences.add(reference); } } res.get("knownReferences").set(knownReferences); return res; }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.java
License:Open Source License
/** * {@inheritDoc}/*from ww w. j a v a2 s .c o m*/ */ @NonNull @Override public GitSCM build() { final SCMHead h = head(); final SCMRevision r = revision(); try { withGitHubRemote(); if (h instanceof PullRequestSCMHead) { PullRequestSCMHead head = (PullRequestSCMHead) h; if (head.isMerge()) { // add the target branch to ensure that the revision we want to merge is also available String name = head.getTarget().getName(); String localName = "remotes/" + remoteName() + "/" + name; Set<String> localNames = new HashSet<>(); boolean match = false; String targetSrc = Constants.R_HEADS + name; String targetDst = Constants.R_REMOTES + remoteName() + "/" + name; for (RefSpec b : asRefSpecs()) { String dst = b.getDestination(); assert dst.startsWith(Constants.R_REFS) : "All git references must start with refs/"; if (targetSrc.equals(b.getSource())) { if (targetDst.equals(dst)) { match = true; } else { // pick up the configured destination name localName = dst.substring(Constants.R_REFS.length()); match = true; } } else { localNames.add(dst.substring(Constants.R_REFS.length())); } } if (!match) { if (localNames.contains(localName)) { // conflict with intended name localName = "remotes/" + remoteName() + "/upstream-" + name; } if (localNames.contains(localName)) { // conflict with intended alternative name localName = "remotes/" + remoteName() + "/pr-" + head.getNumber() + "-upstream-" + name; } if (localNames.contains(localName)) { // ok we're just going to mangle our way to something that works Random entropy = new Random(); while (localNames.contains(localName)) { localName = "remotes/" + remoteName() + "/pr-" + head.getNumber() + "-upstream-" + name + "-" + Integer.toHexString(entropy.nextInt(Integer.MAX_VALUE)); } } withRefSpec("+refs/heads/" + name + ":refs/" + localName); } withExtension(new MergeWithGitSCMExtension(localName, r instanceof PullRequestSCMRevision ? ((PullRequestSCMRevision) r).getBaseHash() : null)); } if (r instanceof PullRequestSCMRevision) { PullRequestSCMRevision rev = (PullRequestSCMRevision) r; withRevision(new AbstractGitSCMSource.SCMRevisionImpl(head, rev.getPullHash())); } } return super.build(); } finally { withHead(h); withRevision(r); } }
From source file:org.nbgit.ui.clone.CloneAction.java
License:Open Source License
public static void doInit(Repository repo, URIish uri, OutputLogger logger) throws IOException, URISyntaxException { repo.create();// ww w . ja v a 2s . c o m repo.getConfig().setBoolean("core", null, "bare", false); repo.getConfig().save(); logger.output("Initialized empty Git repository in " + repo.getWorkDir().getAbsolutePath()); logger.flushLog(); // save remote final RemoteConfig rc = new RemoteConfig(repo.getConfig(), "origin"); rc.addURI(uri); rc.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + "origin" + "/*")); rc.update(repo.getConfig()); repo.getConfig().save(); }
From source file:org.openengsb.connector.git.internal.GitServiceImpl.java
License:Apache License
@Override public List<CommitRef> update() { List<CommitRef> commits = new ArrayList<CommitRef>(); try {/*from w w w .ja v a 2s . c o m*/ if (repository == null) { prepareWorkspace(); initRepository(); } Git git = new Git(repository); AnyObjectId oldHead = repository.resolve(Constants.HEAD); if (oldHead == null) { LOGGER.debug("Local repository is empty. Fetching remote repository."); FetchResult fetchResult = doRemoteUpdate(); if (fetchResult.getTrackingRefUpdate(Constants.R_REMOTES + "origin/" + watchBranch) == null) { LOGGER.debug("Nothing to fetch from remote repository."); return null; } doCheckout(fetchResult); } else { LOGGER.debug("Local repository exists. Pulling remote repository."); git.pull().call(); } AnyObjectId newHead = repository.resolve(Constants.HEAD); if (newHead == null) { LOGGER.debug("New HEAD of local repository doesnt exist."); return null; } if (newHead != oldHead) { LogCommand logCommand = git.log(); if (oldHead == null) { LOGGER.debug("Retrieving revisions from HEAD [{}] on", newHead.name()); logCommand.add(newHead); } else { LOGGER.debug("Retrieving revisions in range [{}, {}]", newHead.name(), oldHead.name()); logCommand.addRange(oldHead, newHead); } Iterable<RevCommit> revisions = logCommand.call(); for (RevCommit revision : revisions) { commits.add(new GitCommitRef(revision)); } } } catch (Exception e) { throw new ScmException(e); } return commits; }
From source file:org.webcat.core.git.GitCloner.java
License:Open Source License
private Repository createWorkingCopyRepositoryIfNecessary(File location, File remoteDir) throws IOException { Repository wcRepository;//from ww w . j a v a 2 s . com try { wcRepository = RepositoryCache.open(FileKey.lenient(location, FS.DETECTED)); } catch (RepositoryNotFoundException e) { // Create the repository from scratch. if (!location.exists()) { location.mkdirs(); } InitCommand init = Git.init(); init.setDirectory(location); init.setBare(false); wcRepository = init.call().getRepository(); StoredConfig config = wcRepository.getConfig(); config.setBoolean("core", null, "bare", false); try { RefSpec refSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + "origin" + "/*"); RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); remoteConfig.addURI(new URIish(remoteDir.toString())); remoteConfig.addFetchRefSpec(refSpec); remoteConfig.update(config); } catch (URISyntaxException e2) { // Do nothing. } config.save(); } return wcRepository; }