mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-30 20:29:46 +01:00
Added force to push command for git and hg repos
Committed-by: Rene Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
committed by
René Pfeuffer
parent
a608a0df80
commit
b2472d85d0
@@ -30,11 +30,14 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.GitConfig;
|
||||
import sonia.scm.repository.api.PushFailedException;
|
||||
import sonia.scm.repository.api.PushResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@@ -82,6 +85,51 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase
|
||||
assertEquals(o1, commits.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForcePush() throws IOException, GitAPIException {
|
||||
write(outgoing, outgoingDirectory, "a.txt", "content of a.txt");
|
||||
RevCommit outgoingCommit = commit(outgoing, "added a");
|
||||
|
||||
write(incoming, incomingDirectory, "a.txt", "conflicting change of a.txt");
|
||||
commit(incoming, "changed a");
|
||||
|
||||
PushCommandRequest request = new PushCommandRequest();
|
||||
request.setRemoteRepository(incomingRepository);
|
||||
request.setForce(true);
|
||||
|
||||
GitPushCommand cmd = createCommand();
|
||||
PushResponse response = cmd.push(request);
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(0L, response.getChangesetCount());
|
||||
|
||||
Iterator<RevCommit> commits = incoming.log().call().iterator();
|
||||
|
||||
assertEquals(outgoingCommit, commits.next());
|
||||
assertThat(commits.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailedPushBecauseOfConflict() throws IOException, GitAPIException {
|
||||
write(outgoing, outgoingDirectory, "a.txt", "content of a.txt");
|
||||
commit(outgoing, "added a");
|
||||
|
||||
write(incoming, incomingDirectory, "a.txt", "conflicting change of a.txt");
|
||||
RevCommit incomingCommit = commit(incoming, "changed a");
|
||||
|
||||
GitPushCommand cmd = createCommand();
|
||||
PushCommandRequest request = new PushCommandRequest();
|
||||
request.setRemoteRepository(incomingRepository);
|
||||
|
||||
assertThatThrownBy(() -> cmd.push(request))
|
||||
.isInstanceOf(PushFailedException.class)
|
||||
.hasMessageContaining("Failed to push");
|
||||
|
||||
Iterator<RevCommit> commits = incoming.log().call().iterator();
|
||||
assertEquals(incomingCommit, commits.next());
|
||||
assertThat(commits.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user