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 org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.ContextEntry;
|
import sonia.scm.ContextEntry;
|
||||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
|
import sonia.scm.repository.GitHeadModifier;
|
||||||
import sonia.scm.repository.GitRepositoryHandler;
|
import sonia.scm.repository.GitRepositoryHandler;
|
||||||
import sonia.scm.repository.GitUtil;
|
import sonia.scm.repository.GitUtil;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -62,6 +63,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
|||||||
private final LfsLoader lfsLoader;
|
private final LfsLoader lfsLoader;
|
||||||
private final PullHttpConnectionProvider pullHttpConnectionProvider;
|
private final PullHttpConnectionProvider pullHttpConnectionProvider;
|
||||||
private final GitRepositoryConfigStoreProvider storeProvider;
|
private final GitRepositoryConfigStoreProvider storeProvider;
|
||||||
|
private final GitHeadModifier gitHeadModifier;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GitPullCommand(GitRepositoryHandler handler,
|
public GitPullCommand(GitRepositoryHandler handler,
|
||||||
@@ -69,12 +71,13 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
|||||||
PostReceiveRepositoryHookEventFactory postReceiveRepositoryHookEventFactory,
|
PostReceiveRepositoryHookEventFactory postReceiveRepositoryHookEventFactory,
|
||||||
LfsLoader lfsLoader,
|
LfsLoader lfsLoader,
|
||||||
PullHttpConnectionProvider pullHttpConnectionProvider,
|
PullHttpConnectionProvider pullHttpConnectionProvider,
|
||||||
GitRepositoryConfigStoreProvider storeProvider) {
|
GitRepositoryConfigStoreProvider storeProvider, GitHeadModifier gitHeadModifier) {
|
||||||
super(handler, context);
|
super(handler, context);
|
||||||
this.postReceiveRepositoryHookEventFactory = postReceiveRepositoryHookEventFactory;
|
this.postReceiveRepositoryHookEventFactory = postReceiveRepositoryHookEventFactory;
|
||||||
this.lfsLoader = lfsLoader;
|
this.lfsLoader = lfsLoader;
|
||||||
this.pullHttpConnectionProvider = pullHttpConnectionProvider;
|
this.pullHttpConnectionProvider = pullHttpConnectionProvider;
|
||||||
this.storeProvider = storeProvider;
|
this.storeProvider = storeProvider;
|
||||||
|
this.gitHeadModifier = gitHeadModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -217,6 +220,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
|
|||||||
Ref head = result.getAdvertisedRef("HEAD").getLeaf();
|
Ref head = result.getAdvertisedRef("HEAD").getLeaf();
|
||||||
if (head.getName().startsWith("refs/heads/")) {
|
if (head.getName().startsWith("refs/heads/")) {
|
||||||
String newDefaultBranch = head.getName().substring("refs/heads/".length());
|
String newDefaultBranch = head.getName().substring("refs/heads/".length());
|
||||||
|
gitHeadModifier.ensure(repository, newDefaultBranch);
|
||||||
storeProvider.setDefaultBranch(repository, newDefaultBranch);
|
storeProvider.setDefaultBranch(repository, newDefaultBranch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@@ -33,6 +31,7 @@ import org.junit.Test;
|
|||||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.GitConfig;
|
import sonia.scm.repository.GitConfig;
|
||||||
|
import sonia.scm.repository.GitHeadModifier;
|
||||||
import sonia.scm.repository.GitTestHelper;
|
import sonia.scm.repository.GitTestHelper;
|
||||||
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||||
|
|
||||||
@@ -42,18 +41,12 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class GitIncomingCommandTest
|
public class GitIncomingCommandTest
|
||||||
extends AbstractRemoteCommandTestBase {
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -105,9 +98,10 @@ public class GitIncomingCommandTest
|
|||||||
handler,
|
handler,
|
||||||
context,
|
context,
|
||||||
postReceiveRepositoryHookEventFactory,
|
postReceiveRepositoryHookEventFactory,
|
||||||
lfsLoader,
|
mock(LfsLoader.class),
|
||||||
pullHttpConnectionProvider,
|
mock(PullHttpConnectionProvider.class),
|
||||||
storeProvider);
|
mock(GitRepositoryConfigStoreProvider.class),
|
||||||
|
mock(GitHeadModifier.class));
|
||||||
PullCommandRequest req = new PullCommandRequest();
|
PullCommandRequest req = new PullCommandRequest();
|
||||||
req.setRemoteRepository(outgoingRepository);
|
req.setRemoteRepository(outgoingRepository);
|
||||||
pull.pull(req);
|
pull.pull(req);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import org.mockito.Mockito;
|
|||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
|
||||||
import sonia.scm.repository.GitConfig;
|
import sonia.scm.repository.GitConfig;
|
||||||
|
import sonia.scm.repository.GitHeadModifier;
|
||||||
import sonia.scm.repository.Modifications;
|
import sonia.scm.repository.Modifications;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -42,6 +43,7 @@ import java.io.IOException;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
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.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
|
||||||
@@ -55,8 +57,6 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
|
|||||||
private LfsLoader lfsLoader;
|
private LfsLoader lfsLoader;
|
||||||
@Mock
|
@Mock
|
||||||
private PullHttpConnectionProvider pullHttpConnectionProvider;
|
private PullHttpConnectionProvider pullHttpConnectionProvider;
|
||||||
@Mock
|
|
||||||
private GitRepositoryConfigStoreProvider storeProvider;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -183,7 +183,8 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
|
|||||||
postReceiveRepositoryHookEventFactory,
|
postReceiveRepositoryHookEventFactory,
|
||||||
lfsLoader,
|
lfsLoader,
|
||||||
pullHttpConnectionProvider,
|
pullHttpConnectionProvider,
|
||||||
storeProvider);
|
mock(GitRepositoryConfigStoreProvider.class),
|
||||||
|
mock(GitHeadModifier.class));
|
||||||
PullCommandRequest pullRequest = new PullCommandRequest();
|
PullCommandRequest pullRequest = new PullCommandRequest();
|
||||||
pullRequest.setRemoteRepository(incomingRepository);
|
pullRequest.setRemoteRepository(incomingRepository);
|
||||||
pullCommand.pull(pullRequest);
|
pullCommand.pull(pullRequest);
|
||||||
|
|||||||
Reference in New Issue
Block a user