mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Remove code duplication
This commit is contained in:
@@ -102,12 +102,22 @@ public class AbstractGitCommand
|
|||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ObjectId getDefaultBranch(Repository gitRepository) throws IOException {
|
||||||
|
Ref ref = getBranchOrDefault(gitRepository, null);
|
||||||
|
if (ref == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return ref.getObjectId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Ref getBranchOrDefault(Repository gitRepository, String requestedBranch) throws IOException {
|
protected Ref getBranchOrDefault(Repository gitRepository, String requestedBranch) throws IOException {
|
||||||
if ( Strings.isNullOrEmpty(requestedBranch) ) {
|
if ( Strings.isNullOrEmpty(requestedBranch) ) {
|
||||||
String defaultBranchName = repository.getProperty(GitConstants.PROPERTY_DEFAULT_BRANCH);
|
String defaultBranchName = repository.getProperty(GitConstants.PROPERTY_DEFAULT_BRANCH);
|
||||||
if (!Strings.isNullOrEmpty(defaultBranchName)) {
|
if (!Strings.isNullOrEmpty(defaultBranchName)) {
|
||||||
return GitUtil.getBranchId(gitRepository, defaultBranchName);
|
return GitUtil.getBranchId(gitRepository, defaultBranchName);
|
||||||
} else {
|
} else {
|
||||||
|
logger.trace("no default branch configured, use repository head as default");
|
||||||
Optional<Ref> repositoryHeadRef = GitUtil.getRepositoryHeadRef(gitRepository);
|
Optional<Ref> repositoryHeadRef = GitUtil.getRepositoryHeadRef(gitRepository);
|
||||||
return repositoryHeadRef.orElse(null);
|
return repositoryHeadRef.orElse(null);
|
||||||
}
|
}
|
||||||
@@ -116,19 +126,6 @@ public class AbstractGitCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObjectId getDefaultBranch(Repository gitRepository) throws IOException {
|
|
||||||
ObjectId head;
|
|
||||||
String defaultBranchName = repository.getProperty(GitConstants.PROPERTY_DEFAULT_BRANCH);
|
|
||||||
if (!Strings.isNullOrEmpty(defaultBranchName)) {
|
|
||||||
Ref ref = GitUtil.getBranchId(gitRepository, defaultBranchName);
|
|
||||||
head = ref == null? null: ref.getObjectId();
|
|
||||||
} else {
|
|
||||||
logger.trace("no default branch configured, use repository head as default");
|
|
||||||
head = GitUtil.getRepositoryHead(gitRepository);
|
|
||||||
}
|
|
||||||
return head;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
Reference in New Issue
Block a user