mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-04 13:49:13 +01:00
Set default branch for repository on init
This commit is contained in:
@@ -30,15 +30,16 @@ import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.attributes.FilterCommandRegistry;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.ConcurrentModificationException;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.NoChangesMadeException;
|
||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||
import sonia.scm.repository.GitRepositoryConfig;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitWorkingCopyFactory;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.web.lfs.LfsBlobStoreFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -50,21 +51,22 @@ import java.util.concurrent.locks.Lock;
|
||||
|
||||
public class GitModifyCommand extends AbstractGitCommand implements ModifyCommand {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GitModifyCommand.class);
|
||||
private static final Striped<Lock> REGISTER_LOCKS = Striped.lock(5);
|
||||
|
||||
private final GitWorkingCopyFactory workingCopyFactory;
|
||||
private final LfsBlobStoreFactory lfsBlobStoreFactory;
|
||||
private final GitRepositoryConfigStoreProvider gitRepositoryConfigStoreProvider;
|
||||
|
||||
@Inject
|
||||
GitModifyCommand(GitContext context, GitRepositoryHandler repositoryHandler, LfsBlobStoreFactory lfsBlobStoreFactory) {
|
||||
this(context, repositoryHandler.getWorkingCopyFactory(), lfsBlobStoreFactory);
|
||||
GitModifyCommand(GitContext context, GitRepositoryHandler repositoryHandler, LfsBlobStoreFactory lfsBlobStoreFactory, GitRepositoryConfigStoreProvider gitRepositoryConfigStoreProvider) {
|
||||
this(context, repositoryHandler.getWorkingCopyFactory(), lfsBlobStoreFactory, gitRepositoryConfigStoreProvider);
|
||||
}
|
||||
|
||||
GitModifyCommand(GitContext context, GitWorkingCopyFactory workingCopyFactory, LfsBlobStoreFactory lfsBlobStoreFactory) {
|
||||
GitModifyCommand(GitContext context, GitWorkingCopyFactory workingCopyFactory, LfsBlobStoreFactory lfsBlobStoreFactory, GitRepositoryConfigStoreProvider gitRepositoryConfigStoreProvider) {
|
||||
super(context);
|
||||
this.workingCopyFactory = workingCopyFactory;
|
||||
this.lfsBlobStoreFactory = lfsBlobStoreFactory;
|
||||
this.gitRepositoryConfigStoreProvider = gitRepositoryConfigStoreProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,9 +114,15 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
|
||||
if (StringUtils.isNotBlank(branch)) {
|
||||
try {
|
||||
getClone().checkout().setName(branch).setCreateBranch(true).call();
|
||||
ConfigurationStore<GitRepositoryConfig> store = gitRepositoryConfigStoreProvider
|
||||
.get(repository);
|
||||
GitRepositoryConfig gitRepositoryConfig = store
|
||||
.getOptional()
|
||||
.orElse(new GitRepositoryConfig());
|
||||
gitRepositoryConfig.setDefaultBranch(branch);
|
||||
store.set(gitRepositoryConfig);
|
||||
} catch (GitAPIException e) {
|
||||
throw new InternalRepositoryException(repository, "could not create default branch for initial commit", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user