List of usage examples for org.eclipse.jgit.lib BranchConfig BranchConfig
public BranchConfig(Config config, String branchName)
From source file:jbyoshi.gitupdate.processor.FastForward.java
License:Apache License
@Override public void process(Repository repo, Git git, String branch, Ref ref, Report report) throws GitAPIException, IOException { String pushDefault = Utils.getPushRemote(repo, branch); if (pushDefault != null) { tryFastForward(repo, ref, repo.getRef(Constants.R_REMOTES + pushDefault + "/" + branch), report); }//ww w . jav a 2s .c om tryFastForward(repo, ref, repo.getRef(new BranchConfig(repo.getConfig(), branch).getTrackingBranch()), report); if (pushDefault == null) { tryFastForward(repo, ref, repo.getRef(Constants.R_REMOTES + "upstream/" + branch), report); } }
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();//from ww w. ja v a2 s . 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(); } }
From source file:jbyoshi.gitupdate.processor.Push.java
License:Apache License
@Override public void registerTasks(Repository repo, Git git, Task root) throws Exception { Task me = root.newChild(getClass().getSimpleName()); // Group the branches by their remotes. Multimap<String, String> branchList = HashMultimap.create(); for (String branch : Utils.getLocalBranches(repo).keySet()) { String remote = Utils.getPushRemote(repo, branch); if (remote == null) { remote = new BranchConfig(repo.getConfig(), branch).getRemote(); }/*from w w w.jav a 2 s . c o m*/ if (remote != null) { branchList.put(remote, branch); } } for (Map.Entry<String, Collection<String>> remote : branchList.asMap().entrySet()) { me.newChild(remote.getKey(), report -> { try { process(repo, git, remote.getKey(), remote.getValue(), report); } catch (Exception e) { report.newErrorChild(e); } }); } }
From source file:jbyoshi.gitupdate.processor.Push.java
License:Apache License
private static void process(Repository repo, Git git, String remote, Collection<String> branches, Report report) throws Exception { // Figure out if anything needs to be pushed. Map<String, ObjectId> oldIds = new HashMap<>(); boolean canPush = false; for (String branch : branches) { BranchConfig config = new BranchConfig(repo.getConfig(), branch); ObjectId target = repo.getRef(branch).getObjectId(); Ref remoteRef = repo.getRef(config.getRemoteTrackingBranch()); if (remoteRef == null || !target.equals(remoteRef.getObjectId())) { canPush = true;/*from w ww .j a v a 2 s . c o m*/ } oldIds.put(branch, remoteRef == null ? ObjectId.zeroId() : remoteRef.getObjectId()); } if (!canPush) { return; } PushCommand push = git.push().setCredentialsProvider(Prompts.INSTANCE).setTimeout(5).setRemote(remote); for (String branch : branches) { push.add(Constants.R_HEADS + branch); } for (PushResult result : push.call()) { for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (update.getStatus() == RemoteRefUpdate.Status.OK) { String branchName = Utils.getShortBranch(update.getSrcRef()); ObjectId oldId = oldIds.get(branchName); String old = oldId.equals(ObjectId.zeroId()) ? "new branch" : oldId.name(); report.newChild(branchName + ": " + old + " -> " + update.getNewObjectId().name()).modified(); } } } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.AgentVcsSupportTest.java
License:Apache License
@TestFor(issues = { "TW-42551", "TW-46857" })
public void should_set_remote_tracking_branch() throws Exception {
AgentRunningBuild build = createRunningBuild(map(PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY,
PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY_ALTERNATES));
myRoot = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(myMainRepo))
.withUseMirrors(true).build();
myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9",
myCheckoutDir, build, false);
Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
then(new BranchConfig(r.getConfig(), "master").getRemoteTrackingBranch())
.isEqualTo("refs/remotes/origin/master");
//TW-46857//from www .j a v a 2s. c o m
myRoot = vcsRoot().withAgentGitPath(getGitPath()).withBranch("personal-branch2")
.withFetchUrl(GitUtils.toURL(myMainRepo)).withUseMirrors(true).build();
myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "3df61e6f11a5a9b919cb3f786a83fdd09f058617",
myCheckoutDir, build, false);
then(new BranchConfig(r.getConfig(), "personal-branch2").getRemoteTrackingBranch())
.isEqualTo("refs/remotes/origin/personal-branch2");
}
From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java
License:Open Source License
/** * @param commit/* www . ja v a 2s .com*/ * @param repository * @param currentBranch * @return ref pointing to the given commit, prefers tracking branch if * multiple refs are available */ protected Ref getRef(PlotCommit commit, Repository repository, String currentBranch) { int count = commit.getRefCount(); if (count == 0) return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit); else if (count == 1) return commit.getRef(0); else { BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch); String trackingBranch = branchConfig.getTrackingBranch(); Ref remoteRef = null; for (int i = 0; i < count; i++) { Ref ref = commit.getRef(i); if (trackingBranch != null && trackingBranch.equals(ref.getName())) return ref; if (ref.getName().startsWith(Constants.R_REMOTES)) remoteRef = ref; } if (remoteRef != null) return remoteRef; else // We tried to pick a nice ref, just pick the first then return commit.getRef(0); } }
From source file:org.eclipse.egit.ui.internal.history.command.RebaseCurrentHandler.java
License:Open Source License
private Ref getRef(PlotCommit commit, Repository repository, String currentBranch) { int count = commit.getRefCount(); if (count == 0) return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit); else if (count == 1) return commit.getRef(0); else {/* w w w. j ava 2 s. co m*/ BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch); String trackingBranch = branchConfig.getTrackingBranch(); Ref remoteRef = null; for (int i = 0; i < count; i++) { Ref ref = commit.getRef(i); if (trackingBranch != null && trackingBranch.equals(ref.getName())) return ref; if (ref.getName().startsWith(Constants.R_REMOTES)) remoteRef = ref; } if (remoteRef != null) return remoteRef; else // We tried to pick a nice ref, just pick the first then return commit.getRef(0); } }
From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java
License:Open Source License
private void setRemoteConfigs() { remoteSelectionCombo.setItems(remoteConfigs); if (this.head != null) { String branchName = Repository.shortenRefName(this.head.getName()); BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName); String remoteName = branchConfig.getRemote(); if (remoteName != null) { for (RemoteConfig rc : remoteConfigs) { if (remoteName.equals(rc.getName())) remoteSelectionCombo.setSelectedRemote(rc); }/*from www . jav a 2 s. c om*/ } } remoteConfig = remoteSelectionCombo.getSelectedRemote(); setRefAssist(remoteConfig); }
From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java
License:Open Source License
private String getSuggestedBranchName() { if (fullBranch != null) { String branchName = Repository.shortenRefName(fullBranch); StoredConfig config = repository.getConfig(); BranchConfig branchConfig = new BranchConfig(config, branchName); String merge = branchConfig.getMerge(); if (!branchConfig.isRemoteLocal() && merge != null && merge.startsWith(Constants.R_HEADS)) { return Repository.shortenRefName(merge); }/* www . jav a 2s .co m*/ } return ""; //$NON-NLS-1$ }
From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java
License:Open Source License
private boolean hasDifferentUpstreamConfiguration() { String branchName = Repository.shortenRefName(this.fullBranch); BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName); String remote = branchConfig.getRemote(); // No upstream config -> don't show warning if (remote == null) { return false; }//from w w w . ja v a2s . c o m if (!remote.equals(remoteConfig.getName())) { return true; } String merge = branchConfig.getMerge(); if (merge == null || !merge.equals(getFullRemoteReference())) { return true; } if (branchConfig.getRebaseMode() != getUpstreamConfig()) { return true; } return false; }