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.fedoraproject.eclipse.packager.git.api.ConvertLocalToRemoteCommand.java
License:Open Source License
/** * Merges remote HEAD with local HEAD (uses the JGit API) * * @param monitor//from w w w .j ava 2 s . c o m * @throws LocalProjectConversionFailedException */ private void mergeLocalRemoteBranches(IProgressMonitor monitor) throws LocalProjectConversionFailedException { MergeCommand merge = git.merge(); try { merge.include(git.getRepository().getRef(Constants.R_REMOTES + "origin/" + Constants.MASTER)); //$NON-NLS-1$ if (monitor.isCanceled()) { throw new OperationCanceledException(); } merge.call(); } catch (Exception e) { throw new LocalProjectConversionFailedException(e.getCause().getMessage(), e); } }
From source file:org.fedoraproject.eclipse.packager.git.FedoraPackagerGitCloneOperation.java
License:Open Source License
/** * Create local branches based on existing remotes (uses the JGit API). * //from w w w .j a v a2 s. c o m * @param monitor * @throws CoreException */ private void createLocalBranches(Git git, IProgressMonitor monitor) throws CoreException { monitor.beginTask(FedoraPackagerGitText.FedoraPackagerGitCloneWizard_createLocalBranchesJob, IProgressMonitor.UNKNOWN); try { // get a list of remote branches ListBranchCommand branchList = git.branchList(); branchList.setListMode(ListMode.REMOTE); // want all remote branches List<Ref> remoteRefs = branchList.call(); for (Ref remoteRef : remoteRefs) { String name = remoteRef.getName(); int index = (Constants.R_REMOTES + "origin/").length(); //$NON-NLS-1$ // Remove "refs/remotes/origin/" part in branch name name = name.substring(index); // Use "f14"-like branch naming if (name.endsWith("/" + Constants.MASTER)) { //$NON-NLS-1$ index = name.indexOf("/" + Constants.MASTER); //$NON-NLS-1$ name = name.substring(0, index); } // Create all remote branches, except "master" if (!name.equals(Constants.MASTER)) { CreateBranchCommand branchCreateCmd = git.branchCreate(); branchCreateCmd.setName(name); // Need to set starting point this way in order for tracking // to work properly. See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=333899 branchCreateCmd.setStartPoint(remoteRef.getName()); // Add remote tracking config in order to not confuse // fedpkg branchCreateCmd.setUpstreamMode(SetupUpstreamMode.TRACK); branchCreateCmd.call(); } } } catch (JGitInternalException e) { e.printStackTrace(); } catch (RefAlreadyExistsException e) { e.printStackTrace(); } catch (RefNotFoundException e) { e.printStackTrace(); } catch (InvalidRefNameException e) { e.printStackTrace(); } }
From source file:org.fedoraproject.eclipse.packager.git.FpGitProjectBits.java
License:Open Source License
/** * Parse available branch names from Git remote branches. * /*from w ww . java 2s .c om*/ * @return */ private HashMap<String, String> getBranches() { HashMap<String, String> branches = new HashMap<String, String>(); try { Map<String, Ref> remotes = git.getRepository().getRefDatabase().getRefs(Constants.R_REMOTES); Set<String> keyset = remotes.keySet(); String branch; for (String key : keyset) { // use shortenRefName() to get rid of refs/*/ prefix branch = Repository.shortenRefName(remotes.get(key).getName()); branch = mapBranchName(branch); // do the branch name mapping if (branch != null) { branches.put(branch, branch); } } } catch (IOException ioException) { ioException.printStackTrace(); } return branches; }
From source file:org.fedoraproject.eclipse.packager.git.FpGitProjectBits.java
License:Open Source License
/** * Returns true if given branch name is NOT an ObjectId in string format. * I.e. if branchName has been created by doing repo.getBranch(), it would * return SHA1 Strings for remote branches. We don't want that. * /* ww w. ja va 2s.c o m*/ * @param branchName * @return */ private boolean isNamedBranch(String branchName) { if (branchName.startsWith(Constants.R_HEADS) || branchName.startsWith(Constants.R_TAGS) || branchName.startsWith(Constants.R_REMOTES)) { return true; } return false; }
From source file:org.fedoraproject.eclipse.packager.git.FpGitProjectBits.java
License:Open Source License
/** * Determine if there are unpushed changes on the current branch. * @return If there are unpushed changes. *//*from w w w .j a va2 s . co m*/ @Override public boolean hasLocalChanges(IProjectRoot fedoraProjectRoot) { if (!isInitialized()) { // FIXME: raise exception instead. return true; // If we are not initialized we can't go any further! } try { // get remote ref from config String branchName = git.getRepository().getBranch(); String trackingRemoteBranch = git.getRepository().getConfig() .getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); /////////////////////////////////////////////////////////// // FIXME: Temp work-around for Eclipse EGit/JGit BZ #317411 FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); //$NON-NLS-1$ fetch.setTimeout(0); // Fetch refs for current branch; account for f14 + f14/master like // branch names. Need to fetch into remotes/origin/f14/master since // this is what is later used for local changes comparison. String fetchBranchSpec = Constants.R_HEADS + branchName + ":" + //$NON-NLS-1$ Constants.R_REMOTES + "origin/" + branchName; //$NON-NLS-1$ if (trackingRemoteBranch != null) { // have f14/master like branch trackingRemoteBranch = trackingRemoteBranch.substring(Constants.R_HEADS.length()); fetchBranchSpec = Constants.R_HEADS + trackingRemoteBranch + ":" + //$NON-NLS-1$ Constants.R_REMOTES + "origin/" + trackingRemoteBranch; //$NON-NLS-1$ } RefSpec spec = new RefSpec(fetchBranchSpec); fetch.setRefSpecs(spec); try { fetch.call(); } catch (JGitInternalException e) { e.printStackTrace(); } catch (InvalidRemoteException e) { e.printStackTrace(); } //--- End temp work-around for EGit/JGit bug. RevWalk rw = new RevWalk(git.getRepository()); ObjectId objHead = git.getRepository().resolve(branchName); if (trackingRemoteBranch == null) { // no config yet, assume plain brach name. trackingRemoteBranch = branchName; } RevCommit commitHead = rw.parseCommit(objHead); ObjectId objRemoteTrackingHead = git.getRepository().resolve("origin/" + //$NON-NLS-1$ trackingRemoteBranch); RevCommit remoteCommitHead = rw.parseCommit(objRemoteTrackingHead); return !commitHead.equals(remoteCommitHead); } catch (NoWorkTreeException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:org.fedoraproject.eclipse.packager.git.GitUtils.java
License:Open Source License
/** * Create local branches based on existing remotes (uses the JGit API). * * @param git//from w ww . ja v a 2 s .c om * @param monitor * @throws CoreException */ public static void createLocalBranches(Git git, IProgressMonitor monitor) throws CoreException { monitor.beginTask(FedoraPackagerGitText.FedoraPackagerGitCloneWizard_createLocalBranchesJob, IProgressMonitor.UNKNOWN); try { // get a list of remote branches ListBranchCommand branchList = git.branchList(); branchList.setListMode(ListMode.REMOTE); // want all remote branches List<Ref> remoteRefs = branchList.call(); for (Ref remoteRef : remoteRefs) { String name = remoteRef.getName(); int index = (Constants.R_REMOTES + "origin/").length(); //$NON-NLS-1$ // Remove "refs/remotes/origin/" part in branch name name = name.substring(index); // Use "f14"-like branch naming if (name.endsWith("/" + Constants.MASTER)) { //$NON-NLS-1$ index = name.indexOf("/" + Constants.MASTER); //$NON-NLS-1$ name = name.substring(0, index); } // Create all remote branches, except "master" if (!name.equals(Constants.MASTER)) { CreateBranchCommand branchCreateCmd = git.branchCreate(); branchCreateCmd.setName(name); // Need to set starting point this way in order for tracking // to work properly. See: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=333899 branchCreateCmd.setStartPoint(remoteRef.getName()); // Add remote tracking config in order to not confuse // fedpkg branchCreateCmd.setUpstreamMode(SetupUpstreamMode.TRACK); if (monitor.isCanceled()) { throw new OperationCanceledException(); } branchCreateCmd.call(); } } } catch (JGitInternalException e) { e.printStackTrace(); } catch (RefAlreadyExistsException e) { e.printStackTrace(); } catch (RefNotFoundException e) { e.printStackTrace(); } catch (InvalidRefNameException e) { e.printStackTrace(); } }
From source file:org.fedoraproject.eclipse.packager.tests.utils.git.GitConvertTestProject.java
License:Open Source License
/** * Adds a remote repository to the existing local packager project * * @throws Exception//from www .j a v a 2s. co m */ public void addRemoteRepository(String uri, Git git) throws Exception { RemoteConfig config = new RemoteConfig(git.getRepository().getConfig(), "origin"); //$NON-NLS-1$ config.addURI(new URIish(uri)); String dst = Constants.R_REMOTES + config.getName(); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$ config.addFetchRefSpec(refSpec); config.update(git.getRepository().getConfig()); git.getRepository().getConfig().save(); // fetch all the remote branches, // create corresponding branches locally and merge them FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); //$NON-NLS-1$ fetch.setTimeout(0); fetch.setRefSpecs(refSpec); fetch.call(); // refresh after checkout project.refreshLocal(IResource.DEPTH_INFINITE, null); }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public boolean configBranch(ServiceInvocationContext context, List<PathFragment> path, GitRef upstreamBranch, RemoteConfig remote, boolean rebase) { try {//from w w w. j ava2 s. c o m RefNode node = (RefNode) GenericTreeStatefulService.getNodeByPathFor(path, null); Repository repository = node.getRepository(); StoredConfig config = repository.getConfig(); Ref ref; if (node instanceof Ref) { ref = node.getRef(); } 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); new Git(repository).fetch().setRemote(new URIish(remote.getUri()).toPrivateString()) .setRefSpecs(refSpec).call(); ref = repository.getRef(remoteRefName); } } String branchName = node.getRef().getName().substring(Constants.R_HEADS.length()); if (upstreamBranch.getName().length() > 0) { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE, upstreamBranch.getName()); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); } if (remote.getName().length() > 0) { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE, remote.getName()); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); } if (rebase) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, true); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE); } config.save(); return true; } catch (Exception e) { logger.debug(CommonPlugin.getInstance().getMessage("error"), path, e); context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } }
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private List<Ref> getBranches(Repository repo) throws IOException { List<Ref> ref = new ArrayList<Ref>(); ref.addAll(repo.getRefDatabase().getRefs(Constants.R_HEADS).values()); ref.addAll(repo.getRefDatabase().getRefs(Constants.R_REMOTES).values()); return ref;//from w ww . j ava 2 s . c o m }
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private String formatHeadRef(Ref ref) { String name = ref.getName();/* w ww .j av a 2 s .c o m*/ if (name.startsWith(Constants.R_HEADS)) { return name.substring(Constants.R_HEADS.length()); } else if (name.startsWith(Constants.R_REMOTES)) { return name.substring(Constants.R_REMOTES.length()); } return name; }