mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-04 13:49:13 +01:00
Use branch from request if specified
This commit is contained in:
@@ -99,19 +99,23 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
failIfNotChanged(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch()));
|
||||
Optional<RevCommit> revCommit = doCommit(request.getCommitMessage(), request.getAuthor(), request.isSign());
|
||||
|
||||
if (initialCommit && StringUtils.isNotBlank(context.getGlobalConfig().getDefaultBranch())) {
|
||||
createDefaultBranch();
|
||||
if (initialCommit) {
|
||||
handleBranchForInitialCommit();
|
||||
}
|
||||
|
||||
push();
|
||||
return revCommit.orElseThrow(() -> new NoChangesMadeException(repository, ModifyWorker.this.request.getBranch())).name();
|
||||
}
|
||||
|
||||
private void createDefaultBranch() {
|
||||
try {
|
||||
getClone().checkout().setName(context.getGlobalConfig().getDefaultBranch()).setCreateBranch(true).call();
|
||||
} catch (GitAPIException e) {
|
||||
throw new InternalRepositoryException(repository, "could not create default branch for initial commit", e);
|
||||
private void handleBranchForInitialCommit() {
|
||||
String branch = StringUtils.isNotBlank(request.getBranch()) ? request.getBranch() : context.getGlobalConfig().getDefaultBranch();
|
||||
if (StringUtils.isNotBlank(branch)) {
|
||||
try {
|
||||
getClone().checkout().setName(branch).setCreateBranch(true).call();
|
||||
} catch (GitAPIException e) {
|
||||
throw new InternalRepositoryException(repository, "could not create default branch for initial commit", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,11 @@ class GitWorkingCopyInitializer {
|
||||
Ref head = clone.exactRef(Constants.HEAD);
|
||||
|
||||
if (head == null || !head.isSymbolic() || (initialBranch != null && !head.getTarget().getName().endsWith(initialBranch))) {
|
||||
throw notFound(entity("Branch", initialBranch).in(context.getRepository()));
|
||||
if (clone.getRefDatabase().getRefs().isEmpty()) {
|
||||
LOG.warn("could not initialize empty clone with given branch {}; this has to be handled later on", initialBranch);
|
||||
} else {
|
||||
throw notFound(entity("Branch", initialBranch).in(context.getRepository()));
|
||||
}
|
||||
}
|
||||
|
||||
return new ParentAndClone<>(null, clone, target);
|
||||
|
||||
Reference in New Issue
Block a user