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 {
String current = db.getBranch();
ObjectId head = db.resolve(Constants.HEAD);
for (String branch : branches) {
if (branch.equals(current)) {
throw die(MessageFormat.format(CLIText.get().cannotDeleteTheBranchWhichYouAreCurrentlyOn, branch));
for (String b : branches) {
if (b.equals(current)) {
throw die(MessageFormat.format(CLIText.get().cannotDeleteTheBranchWhichYouAreCurrentlyOn, b));
}
RefUpdate update = db.updateRef((remote ? Constants.R_REMOTES
: Constants.R_HEADS)
+ branch);
+ b);
update.setNewObjectId(head);
update.setForceUpdate(force || remote);
Result result = update.delete();
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)
throw die(MessageFormat.format(CLIText.get().branchNotFound, branch));
throw die(MessageFormat.format(CLIText.get().branchNotFound, b));
if (remote)
outw.println(MessageFormat.format(CLIText.get().deletedRemoteBranch, branch));
outw.println(MessageFormat.format(CLIText.get().deletedRemoteBranch, b));
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,
final boolean postExists) throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
if (preExists) {
a = new RawText(readFile(name + "_PreImage"));
write(new File(db.getDirectory().getParent(), name),
@ -80,13 +79,15 @@ public class ApplyCommandTest extends RepositoryTestCase {
git.commit().setMessage("PreImage").call();
}
if (postExists)
if (postExists) {
b = new RawText(readFile(name + "_PostImage"));
}
return git
.apply()
.setPatch(getTestResource(name + ".patch")).call();
}
}
@Test
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
public void testDelta_SmallObjectChain() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
byte[] data0 = new byte[512];
Arrays.fill(data0, (byte) 0xf3);
ObjectId id0 = fmt.idFor(Constants.OBJ_BLOB, data0);
@ -247,10 +247,11 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertEquals("stream at EOF", -1, in.read());
in.close();
}
}
@Test
public void testDelta_FailsOver2GiB() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
byte[] base = new byte[] { 'a' };
ObjectId idA = fmt.idFor(Constants.OBJ_BLOB, base);
ObjectId idB = fmt.idFor(Constants.OBJ_BLOB, new byte[] { 'b' });
@ -274,7 +275,8 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
deflate(pack, delta);
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 idxName = new File(dir, idA.name() + ".idx");
@ -306,6 +308,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
packFile.close();
}
}
}
private static byte[] clone(int first, byte[] base) {
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
public void testResetHard() throws IOException, NoFilepatternException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("f", "f()");
writeTrashFile("D/g", "g()");
git.add().addFilepattern(".").call();
@ -187,6 +187,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
assertWorkDir(mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h",
"h()", "untracked", "untracked"));
}
}
/**
* Reset hard from unclean condition.
@ -200,7 +201,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test
public void testResetHardFromIndexEntryWithoutFileToTreeWithoutFile()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("x", "x");
git.add().addFilepattern("x").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();
assertIndex(mkmap("x", "x"));
}
}
/**
* Test first checkout in a repo
@ -224,8 +226,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
*/
@Test
public void testInitialCheckout() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
TestRepository<Repository> db_t = new TestRepository<Repository>(db);
BranchBuilder master = db_t.branch("master");
master.commit().add("f", "1").message("m0").create();
@ -233,6 +234,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
git.checkout().setName("master").call();
assertTrue(new File(db.getWorkTree(), "f").exists());
}
}
private DirCacheCheckout resetHard(RevCommit commit)
throws NoWorkTreeException,
@ -1612,7 +1614,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
public void assertWorkDir(Map<String, String> i)
throws CorruptObjectException,
IOException {
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.setRecursive(false);
walk.addTree(new FileTreeIterator(db));
String expectedValue;
@ -1655,3 +1657,4 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
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;
if (!parents.isEmpty())
firstParentId = parents.get(0);

Loading…
Cancel
Save