Enhance BranchConfig API to expose branch.* options
With these, more code can use BranchConfig instead of directly accessing the raw configuration values. Change-Id: I4b52f97ff0e3fc8f097512806f043c615a3d2594 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
1fd150d565
commit
93530625cf
|
@ -54,6 +54,14 @@
|
|||
*/
|
||||
public class BranchConfig {
|
||||
|
||||
/**
|
||||
* The value that means "local repository" for {@link #getRemote()}:
|
||||
* {@value}
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static final String LOCAL_REPOSITORY = "."; //$NON-NLS-1$
|
||||
|
||||
private final Config config;
|
||||
private final String branchName;
|
||||
|
||||
|
@ -76,12 +84,12 @@ public BranchConfig(final Config config, String branchName) {
|
|||
* not be determined
|
||||
*/
|
||||
public String getTrackingBranch() {
|
||||
String remote = getRemote();
|
||||
String mergeRef = getMergeBranch();
|
||||
String remote = getRemoteOrDefault();
|
||||
String mergeRef = getMerge();
|
||||
if (remote == null || mergeRef == null)
|
||||
return null;
|
||||
|
||||
if (remote.equals(".")) //$NON-NLS-1$
|
||||
if (isRemoteLocal())
|
||||
return mergeRef;
|
||||
|
||||
return findRemoteTrackingBranch(remote, mergeRef);
|
||||
|
@ -93,14 +101,44 @@ public String getTrackingBranch() {
|
|||
* {@link #getTrackingBranch()} instead.
|
||||
*/
|
||||
public String getRemoteTrackingBranch() {
|
||||
String remote = getRemote();
|
||||
String mergeRef = getMergeBranch();
|
||||
String remote = getRemoteOrDefault();
|
||||
String mergeRef = getMerge();
|
||||
if (remote == null || mergeRef == null)
|
||||
return null;
|
||||
|
||||
return findRemoteTrackingBranch(remote, mergeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the "remote" setting points to the local
|
||||
* repository (with {@value #LOCAL_REPOSITORY}), false otherwise
|
||||
* @since 3.5
|
||||
*/
|
||||
public boolean isRemoteLocal() {
|
||||
return LOCAL_REPOSITORY.equals(getRemote());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the remote this branch is configured to fetch from/push to, or
|
||||
* {@code null} if not defined
|
||||
* @since 3.5
|
||||
*/
|
||||
public String getRemote() {
|
||||
return config.getString(ConfigConstants.CONFIG_BRANCH_SECTION,
|
||||
branchName, ConfigConstants.CONFIG_KEY_REMOTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the upstream branch as it is called on the remote, or
|
||||
* {@code null} if not defined
|
||||
* @since 3.5
|
||||
*/
|
||||
public String getMerge() {
|
||||
return config.getString(
|
||||
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
||||
ConfigConstants.CONFIG_KEY_MERGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the tracked remote tracking branch
|
||||
*
|
||||
|
@ -127,20 +165,11 @@ private String findRemoteTrackingBranch(String remote, String mergeRef) {
|
|||
return null;
|
||||
}
|
||||
|
||||
private String getRemote() {
|
||||
String remoteName = config.getString(
|
||||
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
||||
ConfigConstants.CONFIG_KEY_REMOTE);
|
||||
if (remoteName == null)
|
||||
private String getRemoteOrDefault() {
|
||||
String remote = getRemote();
|
||||
if (remote == null)
|
||||
return Constants.DEFAULT_REMOTE_NAME;
|
||||
else
|
||||
return remoteName;
|
||||
}
|
||||
|
||||
private String getMergeBranch() {
|
||||
String mergeRef = config.getString(
|
||||
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
||||
ConfigConstants.CONFIG_KEY_MERGE);
|
||||
return mergeRef;
|
||||
return remote;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue