Browse Source

Merge branch 'stable-4.2'

* stable-4.2:
  DirCacheCheckoutTest: Open Git and TreeWalk in try-with-resource
  CommitCommand: Remove declaration of unthrown exception
  Branch: Fix variable hiding warning
  ApplyCommandTest: Open Git in try-with-resource
  PackFileTest: Open ObjectInserter.Formatter in try-with-resource

Change-Id: I8484b10fad5a4c35fcfaedc1cdf8ccf97471618e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.3
Matthias Sohn 9 years ago
parent
commit
b0facdc113
  1. 16
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
  2. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
  3. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
  4. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
  5. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

16
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java

@ -310,24 +310,24 @@ class Branch extends TextBuiltin {
throws IOException { throws IOException {
String current = db.getBranch(); String current = db.getBranch();
ObjectId head = db.resolve(Constants.HEAD); ObjectId head = db.resolve(Constants.HEAD);
for (String branch : branches) { for (String b : branches) {
if (branch.equals(current)) { if (b.equals(current)) {
throw die(MessageFormat.format(CLIText.get().cannotDeleteTheBranchWhichYouAreCurrentlyOn, branch)); throw die(MessageFormat.format(CLIText.get().cannotDeleteTheBranchWhichYouAreCurrentlyOn, b));
} }
RefUpdate update = db.updateRef((remote ? Constants.R_REMOTES RefUpdate update = db.updateRef((remote ? Constants.R_REMOTES
: Constants.R_HEADS) : Constants.R_HEADS)
+ branch); + b);
update.setNewObjectId(head); update.setNewObjectId(head);
update.setForceUpdate(force || remote); update.setForceUpdate(force || remote);
Result result = update.delete(); Result result = update.delete();
if (result == Result.REJECTED) { if (result == Result.REJECTED) {
throw die(MessageFormat.format(CLIText.get().branchIsNotAnAncestorOfYourCurrentHEAD, branch)); throw die(MessageFormat.format(CLIText.get().branchIsNotAnAncestorOfYourCurrentHEAD, b));
} else if (result == Result.NEW) } else if (result == Result.NEW)
throw die(MessageFormat.format(CLIText.get().branchNotFound, branch)); throw die(MessageFormat.format(CLIText.get().branchNotFound, b));
if (remote) if (remote)
outw.println(MessageFormat.format(CLIText.get().deletedRemoteBranch, branch)); outw.println(MessageFormat.format(CLIText.get().deletedRemoteBranch, b));
else if (verbose) else if (verbose)
outw.println(MessageFormat.format(CLIText.get().deletedBranch, branch)); outw.println(MessageFormat.format(CLIText.get().deletedBranch, b));
} }
} }
} }

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java

@ -69,8 +69,7 @@ public class ApplyCommandTest extends RepositoryTestCase {
private ApplyResult init(final String name, final boolean preExists, private ApplyResult init(final String name, final boolean preExists,
final boolean postExists) throws Exception { final boolean postExists) throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
if (preExists) { if (preExists) {
a = new RawText(readFile(name + "_PreImage")); a = new RawText(readFile(name + "_PreImage"));
write(new File(db.getDirectory().getParent(), name), write(new File(db.getDirectory().getParent(), name),
@ -80,13 +79,15 @@ public class ApplyCommandTest extends RepositoryTestCase {
git.commit().setMessage("PreImage").call(); git.commit().setMessage("PreImage").call();
} }
if (postExists) if (postExists) {
b = new RawText(readFile(name + "_PostImage")); b = new RawText(readFile(name + "_PostImage"));
}
return git return git
.apply() .apply()
.setPatch(getTestResource(name + ".patch")).call(); .setPatch(getTestResource(name + ".patch")).call();
} }
}
@Test @Test
public void testAddA1() throws Exception { public void testAddA1() throws Exception {

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java

@ -191,7 +191,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
@Test @Test
public void testDelta_SmallObjectChain() throws Exception { public void testDelta_SmallObjectChain() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
byte[] data0 = new byte[512]; byte[] data0 = new byte[512];
Arrays.fill(data0, (byte) 0xf3); Arrays.fill(data0, (byte) 0xf3);
ObjectId id0 = fmt.idFor(Constants.OBJ_BLOB, data0); ObjectId id0 = fmt.idFor(Constants.OBJ_BLOB, data0);
@ -247,10 +247,11 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertEquals("stream at EOF", -1, in.read()); assertEquals("stream at EOF", -1, in.read());
in.close(); in.close();
} }
}
@Test @Test
public void testDelta_FailsOver2GiB() throws Exception { public void testDelta_FailsOver2GiB() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter(); try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
byte[] base = new byte[] { 'a' }; byte[] base = new byte[] { 'a' };
ObjectId idA = fmt.idFor(Constants.OBJ_BLOB, base); ObjectId idA = fmt.idFor(Constants.OBJ_BLOB, base);
ObjectId idB = fmt.idFor(Constants.OBJ_BLOB, new byte[] { 'b' }); ObjectId idB = fmt.idFor(Constants.OBJ_BLOB, new byte[] { 'b' });
@ -274,7 +275,8 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
deflate(pack, delta); deflate(pack, delta);
byte[] footer = digest(pack); byte[] footer = digest(pack);
File dir = new File(repo.getObjectDatabase().getDirectory(), "pack"); File dir = new File(repo.getObjectDatabase().getDirectory(),
"pack");
File packName = new File(dir, idA.name() + ".pack"); File packName = new File(dir, idA.name() + ".pack");
File idxName = new File(dir, idA.name() + ".idx"); File idxName = new File(dir, idA.name() + ".idx");
@ -306,6 +308,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
packFile.close(); packFile.close();
} }
} }
}
private static byte[] clone(int first, byte[] base) { private static byte[] clone(int first, byte[] base) {
byte[] r = new byte[base.length]; byte[] r = new byte[base.length];

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

@ -140,7 +140,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test @Test
public void testResetHard() throws IOException, NoFilepatternException, public void testResetHard() throws IOException, NoFilepatternException,
GitAPIException { GitAPIException {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("f", "f()"); writeTrashFile("f", "f()");
writeTrashFile("D/g", "g()"); writeTrashFile("D/g", "g()");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
@ -187,6 +187,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
assertWorkDir(mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", assertWorkDir(mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h",
"h()", "untracked", "untracked")); "h()", "untracked", "untracked"));
} }
}
/** /**
* Reset hard from unclean condition. * Reset hard from unclean condition.
@ -200,7 +201,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test @Test
public void testResetHardFromIndexEntryWithoutFileToTreeWithoutFile() public void testResetHardFromIndexEntryWithoutFileToTreeWithoutFile()
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("x", "x"); writeTrashFile("x", "x");
git.add().addFilepattern("x").call(); git.add().addFilepattern("x").call();
RevCommit id1 = git.commit().setMessage("c1").call(); RevCommit id1 = git.commit().setMessage("c1").call();
@ -216,6 +217,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
git.reset().setMode(ResetType.HARD).setRef(id1.getName()).call(); git.reset().setMode(ResetType.HARD).setRef(id1.getName()).call();
assertIndex(mkmap("x", "x")); assertIndex(mkmap("x", "x"));
} }
}
/** /**
* Test first checkout in a repo * Test first checkout in a repo
@ -224,8 +226,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testInitialCheckout() throws Exception { public void testInitialCheckout() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
TestRepository<Repository> db_t = new TestRepository<Repository>(db); TestRepository<Repository> db_t = new TestRepository<Repository>(db);
BranchBuilder master = db_t.branch("master"); BranchBuilder master = db_t.branch("master");
master.commit().add("f", "1").message("m0").create(); master.commit().add("f", "1").message("m0").create();
@ -233,6 +234,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
git.checkout().setName("master").call(); git.checkout().setName("master").call();
assertTrue(new File(db.getWorkTree(), "f").exists()); assertTrue(new File(db.getWorkTree(), "f").exists());
} }
}
private DirCacheCheckout resetHard(RevCommit commit) private DirCacheCheckout resetHard(RevCommit commit)
throws NoWorkTreeException, throws NoWorkTreeException,
@ -1612,7 +1614,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
public void assertWorkDir(Map<String, String> i) public void assertWorkDir(Map<String, String> i)
throws CorruptObjectException, throws CorruptObjectException,
IOException { IOException {
TreeWalk walk = new TreeWalk(db); try (TreeWalk walk = new TreeWalk(db)) {
walk.setRecursive(false); walk.setRecursive(false);
walk.addTree(new FileTreeIterator(db)); walk.addTree(new FileTreeIterator(db));
String expectedValue; String expectedValue;
@ -1654,4 +1656,5 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
} }
assertEquals("WorkDir has not the right size.", i.size(), nrFiles); assertEquals("WorkDir has not the right size.", i.size(), nrFiles);
} }
}
} }

2
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -312,7 +312,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
} }
} }
private void insertChangeId(ObjectId treeId) throws IOException { private void insertChangeId(ObjectId treeId) {
ObjectId firstParentId = null; ObjectId firstParentId = null;
if (!parents.isEmpty()) if (!parents.isEmpty())
firstParentId = parents.get(0); firstParentId = parents.get(0);

Loading…
Cancel
Save