summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2013-12-13 12:55:50 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2013-12-13 12:55:59 +0100
commitaad7dee3ef492e9333581e8d6b2269dc091ea1d2 (patch)
tree276dd2a8f436659bd211535d46959db7cfbee4c4 /org.eclipse.jgit.test
parentb14a93971837610156e815ae2eee3baaa5b7a44b (diff)
parent0ce61caefbcada30fb1cc4f3b037560f1ba4a8b7 (diff)
downloadjgit-aad7dee3ef492e9333581e8d6b2269dc091ea1d2.tar.gz
jgit-aad7dee3ef492e9333581e8d6b2269dc091ea1d2.zip
Merge branch 'stable-3.2'
* stable-3.2: Canonicalize worktree path in BaseRepositoryBuilder if set via config Add missing @since tags for new public methods in Config Don't use API exception in RebaseTodoLine Fix aborting rebase with detached head Add recursive variant of Config.getNames() methods Prepare post 3.2.0-m3 builds JGit v3.2.0.201311130903-m3 Change-Id: Iad6e284e0fe2c7950f156372b334e47ebd82f3f7 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java213
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java56
2 files changed, 232 insertions, 37 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index a61b44eda8..a728cd2461 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -64,13 +64,13 @@ import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.api.errors.InvalidRebaseStepException;
-import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.AmbiguousObjectException;
+import org.eclipse.jgit.errors.IllegalTodoFileModification;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.junit.RepositoryTestCase;
@@ -576,6 +576,69 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
@Test
+ public void testStopOnConflictAndAbortWithDetachedHEAD() throws Exception {
+ // create file1 on master
+ RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
+ "2", "3");
+ // change first line in master
+ writeFileAndCommit(FILE1, "change file1 in master", "1master", "2", "3");
+ checkFile(FILE1, "1master", "2", "3");
+ // create a topic branch based on second commit
+ createBranch(firstInMaster, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ // we have the old content again
+ checkFile(FILE1, "1", "2", "3");
+
+ // add a line (non-conflicting)
+ writeFileAndCommit(FILE1, "add a line to file1 in topic", "1", "2",
+ "3", "topic4");
+
+ // change first line (conflicting)
+ RevCommit conflicting = writeFileAndCommit(FILE1,
+ "change file1 in topic", "1topic", "2", "3", "topic4");
+
+ RevCommit lastTopicCommit = writeFileAndCommit(FILE1,
+ "change file1 in topic again", "1topic", "2", "3", "topic4");
+
+ git.checkout().setName(lastTopicCommit.getName()).call();
+
+ RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
+ assertEquals(Status.STOPPED, res.getStatus());
+ assertEquals(conflicting, res.getCurrentCommit());
+ checkFile(FILE1,
+ "<<<<<<< Upstream, based on master\n1master\n=======\n1topic",
+ ">>>>>>> e0d1dea change file1 in topic\n2\n3\ntopic4");
+
+ assertEquals(RepositoryState.REBASING_INTERACTIVE,
+ db.getRepositoryState());
+ assertTrue(new File(db.getDirectory(), "rebase-merge").exists());
+ // the first one should be included, so we should have left two picks in
+ // the file
+ assertEquals(1, countPicks());
+
+ // rebase should not succeed in this state
+ try {
+ git.rebase().setUpstream("refs/heads/master").call();
+ fail("Expected exception was not thrown");
+ } catch (WrongRepositoryStateException e) {
+ // expected
+ }
+
+ // abort should reset to topic branch
+ res = git.rebase().setOperation(Operation.ABORT).call();
+ assertEquals(res.getStatus(), Status.ABORTED);
+ assertEquals(lastTopicCommit.getName(), db.getFullBranch());
+ checkFile(FILE1, "1topic", "2", "3", "topic4");
+ RevWalk rw = new RevWalk(db);
+ assertEquals(lastTopicCommit,
+ rw.parseCommit(db.resolve(Constants.HEAD)));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+
+ // rebase- dir in .git must be deleted
+ assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
+ }
+
+ @Test
public void testStopOnConflictAndContinue() throws Exception {
// create file1 on master
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
@@ -1890,8 +1953,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res2 = git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.COMMENT); // delete
- // RevCommit c4
+ try {
+ // delete RevCommit c4
+ steps.get(0).setAction(Action.COMMENT);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2020,7 +2087,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
new RebaseTodoLine("This is a invalid comment");
fail("Constructing a comment line with invalid comment string should fail, but doesn't");
- } catch (JGitInternalException e) {
+ } catch (IllegalArgumentException e) {
// expected
}
RebaseTodoLine validCommentLine = new RebaseTodoLine(
@@ -2035,7 +2102,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
actionLineToBeChanged.setComment("invalid comment");
fail("Setting a invalid comment string should fail but doesn't");
- } catch (JGitInternalException e) {
+ } catch (IllegalArgumentException e) {
assertEquals(null, actionLineToBeChanged.getComment());
}
@@ -2044,7 +2111,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
actionLineToBeChanged.setComment("invalid comment");
fail("Setting a invalid comment string should fail but doesn't");
- } catch (JGitInternalException e) {
+ } catch (IllegalArgumentException e) {
// expected
// setting comment failed, but was successfully set before,
// therefore it may not be altered since then
@@ -2061,7 +2128,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
actionLineToBeChanged.setComment("line1 \n\r line2");
actionLineToBeChanged.setComment("\n\r");
fail("Setting a multiline comment string should fail but doesn't");
- } catch (JGitInternalException e) {
+ } catch (IllegalArgumentException e) {
// expected
}
// Try setting valid comments
@@ -2113,9 +2180,15 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
+
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.REWORD);
+ try {
+ steps.get(0).setAction(Action.REWORD);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
+
public String modifyCommitMessage(String commit) {
return "rewritten commit message";
}
@@ -2155,7 +2228,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.EDIT);
+ try {
+ steps.get(0).setAction(Action.EDIT);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2215,7 +2292,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(1).setAction(Action.SQUASH);
+ try {
+ steps.get(1).setAction(Action.SQUASH);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2290,8 +2371,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(1).setAction(Action.SQUASH);
- steps.get(2).setAction(Action.SQUASH);
+ try {
+ steps.get(1).setAction(Action.SQUASH);
+ steps.get(2).setAction(Action.SQUASH);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2367,8 +2452,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(1).setAction(Action.FIXUP);
- steps.get(2).setAction(Action.SQUASH);
+ try {
+ steps.get(1).setAction(Action.FIXUP);
+ steps.get(2).setAction(Action.SQUASH);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2437,7 +2526,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(1).setAction(Action.FIXUP);
+ try {
+ steps.get(1).setAction(Action.FIXUP);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2481,7 +2574,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(1).setAction(Action.FIXUP);
+ try {
+ steps.get(1).setAction(Action.FIXUP);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2516,7 +2613,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.FIXUP);
+ try {
+ steps.get(0).setAction(Action.FIXUP);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2544,7 +2645,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.SQUASH);
+ try {
+ steps.get(0).setAction(Action.SQUASH);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2571,7 +2676,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.EDIT);
+ try {
+ steps.get(0).setAction(Action.EDIT);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2610,7 +2719,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.remove(0);
- steps.get(0).setAction(Action.EDIT);
+ try {
+ steps.get(0).setAction(Action.EDIT);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2648,7 +2761,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.remove(0);
- steps.get(0).setAction(Action.REWORD);
+ try {
+ steps.get(0).setAction(Action.REWORD);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2661,7 +2778,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.remove(0);
- steps.get(0).setAction(Action.REWORD);
+ try {
+ steps.get(0).setAction(Action.REWORD);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2702,9 +2823,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.PICK);
- steps.remove(1);
- steps.get(1).setAction(Action.SQUASH);
+ try {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.SQUASH);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2716,9 +2841,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
result = git.rebase().runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.PICK);
- steps.remove(1);
- steps.get(1).setAction(Action.SQUASH);
+ try {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.SQUASH);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2760,9 +2889,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.PICK);
- steps.remove(1);
- steps.get(1).setAction(Action.FIXUP);
+ try {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.FIXUP);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2774,9 +2907,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
result = git.rebase().runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.PICK);
- steps.remove(1);
- steps.get(1).setAction(Action.FIXUP);
+ try {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.FIXUP);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
@@ -2823,8 +2960,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
- steps.get(0).setAction(Action.EDIT);
- steps.get(1).setAction(Action.PICK);
+ try {
+ steps.get(0).setAction(Action.EDIT);
+ steps.get(1).setAction(Action.PICK);
+ } catch (IllegalTodoFileModification e) {
+ fail("unexpected exception: " + e);
+ }
}
public String modifyCommitMessage(String commit) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 6ebef6cbf9..630bd7dc0d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -520,6 +520,31 @@ public class ConfigTest {
}
@Test
+ public void test_ReadNamesInSectionRecursive()
+ throws ConfigInvalidException {
+ String baseConfigString = "[core]\n" + "logAllRefUpdates = true\n";
+ String configString = "[core]\n" + "repositoryFormatVersion = 0\n"
+ + "filemode = false\n";
+ final Config c = parse(configString, parse(baseConfigString));
+ Set<String> names = c.getNames("core", true);
+ assertEquals("Core section size", 3, names.size());
+ assertTrue("Core section should contain \"filemode\"",
+ names.contains("filemode"));
+ assertTrue("Core section should contain \"repositoryFormatVersion\"",
+ names.contains("repositoryFormatVersion"));
+ assertTrue("Core section should contain \"logAllRefUpdates\"",
+ names.contains("logAllRefUpdates"));
+ assertTrue("Core section should contain \"logallrefupdates\"",
+ names.contains("logallrefupdates"));
+
+ Iterator<String> itr = names.iterator();
+ assertEquals("filemode", itr.next());
+ assertEquals("repositoryFormatVersion", itr.next());
+ assertEquals("logAllRefUpdates", itr.next());
+ assertFalse(itr.hasNext());
+ }
+
+ @Test
public void test010_readNamesInSubSection() throws ConfigInvalidException {
String configString = "[a \"sub1\"]\n"//
+ "x = 0\n" //
@@ -541,6 +566,30 @@ public class ConfigTest {
}
@Test
+ public void readNamesInSubSectionRecursive() throws ConfigInvalidException {
+ String baseConfigString = "[a \"sub1\"]\n"//
+ + "x = 0\n" //
+ + "y = false\n"//
+ + "[a \"sub2\"]\n"//
+ + "A=0\n";//
+ String configString = "[a \"sub1\"]\n"//
+ + "z = true\n"//
+ + "[a \"sub2\"]\n"//
+ + "B=1\n";
+ final Config c = parse(configString, parse(baseConfigString));
+ Set<String> names = c.getNames("a", "sub1", true);
+ assertEquals("Subsection size", 3, names.size());
+ assertTrue("Subsection should contain \"x\"", names.contains("x"));
+ assertTrue("Subsection should contain \"y\"", names.contains("y"));
+ assertTrue("Subsection should contain \"z\"", names.contains("z"));
+ names = c.getNames("a", "sub2", true);
+ assertEquals("Subsection size", 2, names.size());
+ assertTrue("Subsection should contain \"A\"", names.contains("A"));
+ assertTrue("Subsection should contain \"a\"", names.contains("a"));
+ assertTrue("Subsection should contain \"B\"", names.contains("B"));
+ }
+
+ @Test
public void testQuotingForSubSectionNames() {
String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
String result;
@@ -584,7 +633,12 @@ public class ConfigTest {
private static Config parse(final String content)
throws ConfigInvalidException {
- final Config c = new Config(null);
+ return parse(content, null);
+ }
+
+ private static Config parse(final String content, Config baseConfig)
+ throws ConfigInvalidException {
+ final Config c = new Config(baseConfig);
c.fromText(content);
return c;
}