mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Set the HEAD in Git pull command
Committed-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com> Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
committed by
SCM-Manager
parent
f28eaeca15
commit
cb8c951cb8
2
gradle/changelog/default_branch_after_import.yaml
Normal file
2
gradle/changelog/default_branch_after_import.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Set the default branch in imported Git repositories correctly to the HEAD of the source repository
|
||||
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||
import sonia.scm.repository.GitHeadModifier;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -62,6 +63,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
private final LfsLoader lfsLoader;
|
||||
private final PullHttpConnectionProvider pullHttpConnectionProvider;
|
||||
private final GitRepositoryConfigStoreProvider storeProvider;
|
||||
private final GitHeadModifier gitHeadModifier;
|
||||
|
||||
@Inject
|
||||
public GitPullCommand(GitRepositoryHandler handler,
|
||||
@@ -69,12 +71,13 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
PostReceiveRepositoryHookEventFactory postReceiveRepositoryHookEventFactory,
|
||||
LfsLoader lfsLoader,
|
||||
PullHttpConnectionProvider pullHttpConnectionProvider,
|
||||
GitRepositoryConfigStoreProvider storeProvider) {
|
||||
GitRepositoryConfigStoreProvider storeProvider, GitHeadModifier gitHeadModifier) {
|
||||
super(handler, context);
|
||||
this.postReceiveRepositoryHookEventFactory = postReceiveRepositoryHookEventFactory;
|
||||
this.lfsLoader = lfsLoader;
|
||||
this.pullHttpConnectionProvider = pullHttpConnectionProvider;
|
||||
this.storeProvider = storeProvider;
|
||||
this.gitHeadModifier = gitHeadModifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,6 +220,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
||||
Ref head = result.getAdvertisedRef("HEAD").getLeaf();
|
||||
if (head.getName().startsWith("refs/heads/")) {
|
||||
String newDefaultBranch = head.getName().substring("refs/heads/".length());
|
||||
gitHeadModifier.ensure(repository, newDefaultBranch);
|
||||
storeProvider.setDefaultBranch(repository, newDefaultBranch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Ignore;
|
||||
@@ -33,6 +31,7 @@ import org.junit.Test;
|
||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitConfig;
|
||||
import sonia.scm.repository.GitHeadModifier;
|
||||
import sonia.scm.repository.GitTestHelper;
|
||||
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||
|
||||
@@ -42,18 +41,12 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitIncomingCommandTest
|
||||
extends AbstractRemoteCommandTestBase {
|
||||
|
||||
private final LfsLoader lfsLoader = mock(LfsLoader.class);
|
||||
private final PullHttpConnectionProvider pullHttpConnectionProvider = mock(PullHttpConnectionProvider.class);
|
||||
private final GitRepositoryConfigStoreProvider storeProvider = mock(GitRepositoryConfigStoreProvider.class);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -105,9 +98,10 @@ public class GitIncomingCommandTest
|
||||
handler,
|
||||
context,
|
||||
postReceiveRepositoryHookEventFactory,
|
||||
lfsLoader,
|
||||
pullHttpConnectionProvider,
|
||||
storeProvider);
|
||||
mock(LfsLoader.class),
|
||||
mock(PullHttpConnectionProvider.class),
|
||||
mock(GitRepositoryConfigStoreProvider.class),
|
||||
mock(GitHeadModifier.class));
|
||||
PullCommandRequest req = new PullCommandRequest();
|
||||
req.setRemoteRepository(outgoingRepository);
|
||||
pull.pull(req);
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||
import sonia.scm.repository.GitConfig;
|
||||
import sonia.scm.repository.GitHeadModifier;
|
||||
import sonia.scm.repository.Modifications;
|
||||
|
||||
import java.io.File;
|
||||
@@ -42,6 +43,7 @@ import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
@@ -55,8 +57,6 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
|
||||
private LfsLoader lfsLoader;
|
||||
@Mock
|
||||
private PullHttpConnectionProvider pullHttpConnectionProvider;
|
||||
@Mock
|
||||
private GitRepositoryConfigStoreProvider storeProvider;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
@@ -183,7 +183,8 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
|
||||
postReceiveRepositoryHookEventFactory,
|
||||
lfsLoader,
|
||||
pullHttpConnectionProvider,
|
||||
storeProvider);
|
||||
mock(GitRepositoryConfigStoreProvider.class),
|
||||
mock(GitHeadModifier.class));
|
||||
PullCommandRequest pullRequest = new PullCommandRequest();
|
||||
pullRequest.setRemoteRepository(incomingRepository);
|
||||
pullCommand.pull(pullRequest);
|
||||
|
||||
Reference in New Issue
Block a user