-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing git-executor as an alternative to egit/jgit
- Loading branch information
Showing
12 changed files
with
744 additions
and
12 deletions.
There are no files selected for viewing
184 changes: 184 additions & 0 deletions
184
....modelrepository.tests/src/org/archicontribs/modelrepository/grafico/GitExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package org.archicontribs.modelrepository.grafico; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.logging.Logger; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class GitExecutorTest { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(GitExecutorTest.class.getName()); | ||
|
||
private GitExecutor underTest; | ||
|
||
public GitExecutorTest() throws GitExecutionException { | ||
underTest = new GitExecutor(TestData.GIT_PATH, TestData.GIT_REPO); | ||
} | ||
|
||
@Test | ||
public void canFindGitOnPath() throws IOException, InterruptedException { | ||
Process process = Runtime.getRuntime().exec(new String[] { "which", "git" }); | ||
assertEquals(0, process.waitFor()); | ||
} | ||
|
||
@Test | ||
public void canGitVersion() throws GitExecutionException { | ||
GitExecutionResult res = underTest.version(); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canGitReset() throws GitExecutionException { | ||
GitExecutionResult res = underTest.reset(true, TestData.GIT_HISTORICAL_COMMIT_ID); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canGitClean() throws GitExecutionException, IOException { | ||
File f = new File(TestData.GIT_FOLDER, "cleanMe"); | ||
assertTrue(f.createNewFile()); | ||
assertTrue(f.exists()); | ||
|
||
GitExecutionResult res = underTest.clean(); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
|
||
assertFalse(f.exists()); | ||
} | ||
|
||
private void resetTestScenario() { | ||
try { | ||
canGitReset(); | ||
canGitClean(); | ||
} catch (GitExecutionException e) { | ||
throw new RuntimeException(e); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
public void canGitFetch() throws GitExecutionException { | ||
GitExecutionResult res = underTest.fetch(); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
} | ||
|
||
|
||
@Test | ||
public void canGitCommit() throws GitExecutionException { | ||
resetTestScenario(); // arrange | ||
|
||
GitExecutionResult res = underTest.commit("empty commit", false, true, false); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canGitPull() throws GitExecutionException { | ||
resetTestScenario(); // arrange | ||
|
||
GitExecutionResult res = underTest.pull(); // FF_ONLY | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canGitPullDetectConflict() throws GitExecutionException { | ||
resetTestScenario(); // arrange | ||
|
||
GitExecutionResult resCommit = underTest.commit("empty commit", false, true, false); | ||
LOGGER.finest(resCommit.outputLine()); | ||
|
||
GitExecutionResult res = underTest.pull(); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(128, res.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canGitPullRebase() throws GitExecutionException { | ||
resetTestScenario(); // arrange | ||
|
||
GitExecutionResult resCommit = underTest.commit("empty commit", false, true, false); | ||
LOGGER.finest(resCommit.outputLine()); | ||
|
||
GitExecutionResult res = underTest.pull(GitExecutor.PullMode.REBASE_MERGE); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(0, res.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canGitRebaseAbort() throws GitExecutionException, IOException { | ||
resetTestScenario(); // arrange | ||
|
||
File targetF = Paths.get(TestData.GIT_FOLDER.getPath(), TestData.GIT_FILE.getName()).toFile(); | ||
Files.move(TestData.GIT_FILE.toPath(), targetF.toPath(), | ||
StandardCopyOption.REPLACE_EXISTING); | ||
|
||
GitExecutionResult resAdd = underTest.add(TestData.GIT_FILE); | ||
assertEquals(0, resAdd.exitCode()); | ||
|
||
GitExecutionResult resCommit = underTest.commit("file deleted accidentaly oopsy"); | ||
LOGGER.finest(resCommit.outputLine()); | ||
|
||
GitExecutionResult res = underTest.rebase(TestData.GIT_HISTORICAL_ONTO_COMMIT_ID); | ||
LOGGER.finest(res.outputLine()); | ||
assertEquals(1, res.exitCode()); | ||
|
||
GitExecutionResult abortResult = underTest.rebaseAbort(); | ||
assertEquals(0, abortResult.exitCode()); | ||
} | ||
|
||
@Test | ||
public void canDetectUncommittedFile() throws GitExecutionException, IOException { | ||
resetTestScenario(); // arrange | ||
|
||
assertFalse(underTest.hasChanges()); | ||
|
||
Files.move(TestData.GIT_FILE.toPath(), Paths.get(TestData.GIT_FOLDER.getPath(), TestData.GIT_FILE.getName()), | ||
StandardCopyOption.REPLACE_EXISTING); | ||
|
||
assertTrue(underTest.hasChanges()); | ||
} | ||
|
||
@Test | ||
public void canStageAllFiles() throws GitExecutionException, IOException { | ||
resetTestScenario(); // arrange | ||
|
||
Files.move(TestData.GIT_FILE.toPath(), Paths.get(TestData.GIT_FOLDER.getPath(), TestData.GIT_FILE.getName()), | ||
StandardCopyOption.REPLACE_EXISTING); | ||
|
||
assertEquals(0, underTest.addAll().exitCode()); | ||
} | ||
|
||
@Test | ||
public void canStageFile() throws GitExecutionException, IOException { | ||
resetTestScenario(); // arrange | ||
|
||
File targetF = Paths.get(TestData.GIT_FOLDER.getPath(), TestData.GIT_FILE.getName()).toFile(); | ||
assertTrue(targetF.createNewFile()); | ||
|
||
assertEquals(0, underTest.add(targetF).exitCode()); | ||
|
||
File nonExistentF = Paths.get(TestData.GIT_FOLDER.getPath(), "nonExistentFile").toFile(); | ||
assertFalse(nonExistentF.exists()); | ||
|
||
assertNotEquals(0, underTest.add(nonExistentF).exitCode()); | ||
} | ||
|
||
@Test | ||
public void canRemoteSshCredentials() { | ||
// TODO | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ontribs.modelrepository.tests/src/org/archicontribs/modelrepository/grafico/TestData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.archicontribs.modelrepository.grafico; | ||
|
||
import java.io.File; | ||
|
||
interface TestData { | ||
|
||
final File GIT_REPO = new File("/home/jan/projs/egit"); | ||
final File GIT_FILE = new File(GIT_REPO, "pom.xml"); | ||
final File GIT_FOLDER = new File(GIT_REPO, "icons"); | ||
final File GIT_PATH = new File("/usr/local/bin/git"); | ||
final String GIT_HISTORICAL_COMMIT_ID = "e90d864edca6eb34d0b7a1f0dcc767bcd4970bb5"; | ||
final String GIT_HISTORICAL_ONTO_COMMIT_ID = "cd8c66d521371cbd1163b136f991a9598055d84a"; | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...tory.tests/src/org/archicontribs/modelrepository/grafico/launchers/GitExecutorTest.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/org.archicontribs.modelrepository.tests/src/org/archicontribs/modelrepository/grafico/GitExecutorTest.java"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="1"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.archicontribs.modelrepository.grafico.GitExecutorTest"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.archicontribs.modelrepository.tests"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> | ||
</launchConfiguration> |
Oops, something went wrong.