List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_BRANCH_SECTION
String CONFIG_BRANCH_SECTION
To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_BRANCH_SECTION.
Click Source Link
From source file:org.eclipse.egit.ui.internal.push.PushToUpstreamTest.java
License:Open Source License
@Test public void pushWithExistingUpstreamConfiguration() throws Exception { checkoutNewLocalBranch("bar"); // Existing configuration repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, "bar", ConfigConstants.CONFIG_KEY_REMOTE, "fetch"); repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, "bar", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/bar"); pushToUpstream();//from w w w . j a v a 2s .c o m assertBranchPushed("bar", remoteRepository); }
From source file:org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog.java
License:Open Source License
/** * Add a warning about this remote being used by other branches * * @param parent//from w w w. j a va 2 s . com */ private void addDefaultOriginWarningIfNeeded(Composite parent) { if (!showBranchInfo) return; List<String> otherBranches = new ArrayList<String>(); String currentBranch; try { currentBranch = repository.getBranch(); } catch (IOException e) { // just don't show this warning return; } String currentRemote = config.getName(); Config repositoryConfig = repository.getConfig(); Set<String> branches = repositoryConfig.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION); for (String branch : branches) { if (branch.equals(currentBranch)) continue; String remote = repositoryConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); if ((remote == null && currentRemote.equals(Constants.DEFAULT_REMOTE_NAME)) || (remote != null && remote.equals(currentRemote))) otherBranches.add(branch); } if (otherBranches.isEmpty()) return; Composite warningAboutOrigin = new Composite(parent, SWT.NONE); warningAboutOrigin.setLayout(new GridLayout(2, false)); Label warningLabel = new Label(warningAboutOrigin, SWT.NONE); warningLabel .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK)); Text warningText = new Text(warningAboutOrigin, SWT.READ_ONLY); warningText.setText(NLS.bind(UIText.SimpleConfigurePushDialog_ReusedOriginWarning, config.getName(), Integer.valueOf(otherBranches.size()))); warningText.setToolTipText(otherBranches.toString()); GridDataFactory.fillDefaults().grab(true, false).applyTo(warningLabel); }
From source file:org.eclipse.egit.ui.internal.repository.BranchPropertySource.java
License:Open Source License
public Object getPropertyValue(Object id) { String actId = ((String) id); String value = myRepository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, actId);/*from w w w . ja va2s. c o m*/ if (value == null || value.length() == 0) return UIText.BranchPropertySource_ValueNotSet; return value; }
From source file:org.eclipse.egit.ui.view.synchronize.SynchronizeViewPushTest.java
License:Open Source License
@Before public void prepare() throws Exception { FileRepository childRepository = lookupRepository(childRepositoryFile); FileRepository repository = lookupRepository(repositoryFile); FileBasedConfig config = repository.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); remoteConfig.addURI(new URIish(childRepository.getDirectory().getParentFile().toURI().toURL())); remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); remoteConfig.update(config);//from ww w . ja va 2 s .c o m config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE, "origin"); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master"); config.save(); FetchOperation fetchOperation = new FetchOperation(repository, remoteConfig, 60, false); fetchOperation.run(null); }
From source file:org.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java
License:Open Source License
/** * Configure pull request topic branch to use head remote * * @param repo//from w w w .ja v a 2 s . c o m * @param request * @throws IOException */ public static void configureTopicBranch(Repository repo, PullRequest request) throws IOException { String branch = getBranchName(request); String remote = request.getHead().getRepo().getOwner().getLogin(); StoredConfig config = repo.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGE, getHeadBranch(request)); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE, remote); config.save(); }
From source file:org.eclipse.oomph.gitbash.decorators.BranchDecorator.java
License:Open Source License
private String getDecoration(org.eclipse.egit.ui.internal.repository.tree.RefNode node) { String branchName = Repository.shortenRefName(node.getObject().getName()); Repository repository = node.getRepository(); StoredConfig config = repository.getConfig(); String branch = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); if (branch != null) { String remote = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); boolean rebaseFlag = config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, false); if (branch.startsWith(DEFAULT_PATH)) { branch = branch.substring(DEFAULT_PATH.length()); }/*from ww w. j a v a 2 s . c o m*/ String prefix = ".".equals(remote) ? "" : remote + "/"; String result = (rebaseFlag ? "REBASE" : "MERGE") + ": " + prefix + branch; try { BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branchName); if (trackingStatus != null && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) { result += " " + formatBranchTrackingStatus(trackingStatus); } } catch (Throwable t) { //$FALL-THROUGH$ } return result; } return null; }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static void createBranch(SetupTaskContext context, Git git, String checkoutBranch, String remoteName) throws Exception { context.log("Creating local branch " + checkoutBranch); CreateBranchCommand command = git.branchCreate(); command.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM); command.setName(checkoutBranch);//w ww . jav a 2s .c o m command.setStartPoint("refs/remotes/" + remoteName + "/" + checkoutBranch); command.call(); StoredConfig config = git.getRepository().getConfig(); config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, checkoutBranch, ConfigConstants.CONFIG_KEY_REBASE, true); config.save(); }
From source file:org.eclipse.orion.server.git.BaseToRemoteConverter.java
License:Open Source License
public static URI getRemoteBranchLocation(URI base, String branchName, Repository db, BaseToRemoteConverter converter) throws IOException, URISyntaxException { Config repoConfig = db.getConfig();//from w w w . j a v a2 s. c o m String remote = repoConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); if (remote == null) // fall back to default remote remote = Constants.DEFAULT_REMOTE_NAME; String fetch = repoConfig.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, "fetch"); //$NON-NLS-1$ if (fetch != null) { // expecting something like: +refs/heads/*:refs/remotes/origin/* String[] split = fetch.split(":"); //$NON-NLS-1$ if (split[0].endsWith("*") /*src*/ && split[1].endsWith("*") /*dst*/) { //$NON-NLS-1$ //$NON-NLS-2$ return converter.baseToRemoteLocation(base, remote, branchName); } } return null; }
From source file:org.eclipse.orion.server.git.objects.Branch.java
License:Open Source License
@PropertyDescription(name = GitConstants.KEY_REMOTE) private JSONArray getRemotes() throws URISyntaxException, JSONException, IOException, CoreException { String branchName = Repository.shortenRefName(ref.getName()); JSONArray result = new JSONArray(); String remoteName = getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); if (remoteName != null) { RemoteConfig remoteConfig = new RemoteConfig(getConfig(), remoteName); if (!remoteConfig.getFetchRefSpecs().isEmpty()) { Remote remote = new Remote(cloneLocation, db, remoteName); remote.setNewBranch(branchName); result.put(remote.toJSON()); }/*from w w w.j ava2 s. c o m*/ } else { List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig()); for (RemoteConfig remoteConfig : remoteConfigs) { if (!remoteConfig.getFetchRefSpecs().isEmpty()) { Remote r = new Remote(cloneLocation, db, remoteConfig.getName()); r.setNewBranch(branchName); if (db.resolve(Constants.R_REMOTES + remoteConfig.getName() + "/" + branchName) != null) { //$NON-NLS-1$ // it's an existing branch, not a new one, use it as filter return new JSONArray().put(r.toJSON()); } result.put(r.toJSON()); } } } return result; }
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. */// ww w. j a v a 2s . 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; }