summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java36
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java9
2 files changed, 39 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java
index ae05fd95e0..b0883e3f43 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011, Robin Stocker <robin@nibor.org>
+ * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -71,8 +72,25 @@ public class BranchConfig {
}
/**
- * @return the full remote-tracking branch name or <code>null</code> if it
- * could not be determined
+ * @return the full tracking branch name or <code>null</code> if it could
+ * not be determined
+ */
+ public String getTrackingBranch() {
+ String remote = getRemote();
+ String mergeRef = getMergeBranch();
+ if (remote == null || mergeRef == null)
+ return null;
+
+ if (remote.equals("."))
+ return mergeRef;
+
+ return findRemoteTrackingBranch(remote, mergeRef);
+ }
+
+ /**
+ * @return the full remote-tracking branch name or {@code null} if it could
+ * not be determined. If you also want local tracked branches use
+ * {@link #getTrackingBranch()} instead.
*/
public String getRemoteTrackingBranch() {
String remote = getRemote();
@@ -80,6 +98,20 @@ public class BranchConfig {
if (remote == null || mergeRef == null)
return null;
+ return findRemoteTrackingBranch(remote, mergeRef);
+ }
+
+ /**
+ * Finds the tracked remote tracking branch
+ *
+ * @param remote
+ * Remote name
+ * @param mergeRef
+ * merge Ref of the local branch tracking the remote tracking
+ * branch
+ * @return full remote tracking branch name or null
+ */
+ private String findRemoteTrackingBranch(String remote, String mergeRef) {
RemoteConfig remoteConfig;
try {
remoteConfig = new RemoteConfig(config, remote);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java
index 4d69e602ee..7844fd819f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011, Robin Stocker <robin@nibor.org>
+ * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -72,11 +73,11 @@ public class BranchTrackingStatus {
BranchConfig branchConfig = new BranchConfig(repository.getConfig(),
branchName);
- String remoteTrackingBranch = branchConfig.getRemoteTrackingBranch();
- if (remoteTrackingBranch == null)
+ String trackingBranch = branchConfig.getTrackingBranch();
+ if (trackingBranch == null)
return null;
- Ref tracking = repository.getRef(remoteTrackingBranch);
+ Ref tracking = repository.getRef(trackingBranch);
if (tracking == null)
return null;
@@ -99,7 +100,7 @@ public class BranchTrackingStatus {
int aheadCount = RevWalkUtils.count(walk, localCommit, mergeBase);
int behindCount = RevWalkUtils.count(walk, trackingCommit, mergeBase);
- return new BranchTrackingStatus(remoteTrackingBranch, aheadCount, behindCount);
+ return new BranchTrackingStatus(trackingBranch, aheadCount, behindCount);
}
private final String remoteTrackingBranch;