Browse Source

Use FileRepository where we assume other file semantics

When the surrounding code is already heavily based upon the
assumption that we have a FileRepository (e.g. because it
created that type of repository) keep the type around and
use it directly.  This permits us to continue to do things
like save the configuration file.

Change-Id: Ib783f0f6a11acd6aa305c16d61ccc368b46beecc
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
89d4a7377f
  1. 5
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java
  2. 5
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java
  3. 17
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
  4. 9
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
  5. 6
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/util/HttpTestCase.java
  6. 8
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
  7. 102
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  8. 17
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
  9. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java
  10. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
  11. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
  12. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
  13. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java

5
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java

@ -60,6 +60,7 @@ import org.eclipse.jgit.http.test.util.HttpTestCase;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -71,14 +72,14 @@ import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
public class AdvertiseErrorTest extends HttpTestCase { public class AdvertiseErrorTest extends HttpTestCase {
private Repository remoteRepository; private FileRepository remoteRepository;
private URIish remoteURI; private URIish remoteURI;
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName(); final String srcName = src.getRepository().getDirectory().getName();
ServletContextHandler app = server.addContext("/git"); ServletContextHandler app = server.addContext("/git");

5
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java

@ -62,6 +62,7 @@ import org.eclipse.jgit.http.test.util.HttpTestCase;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -76,14 +77,14 @@ import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
public class HookMessageTest extends HttpTestCase { public class HookMessageTest extends HttpTestCase {
private Repository remoteRepository; private FileRepository remoteRepository;
private URIish remoteURI; private URIish remoteURI;
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName(); final String srcName = src.getRepository().getDirectory().getName();
ServletContextHandler app = server.addContext("/git"); ServletContextHandler app = server.addContext("/git");

17
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java

@ -62,6 +62,7 @@ import org.eclipse.jgit.http.test.util.AccessEvent;
import org.eclipse.jgit.http.test.util.HttpTestCase; import org.eclipse.jgit.http.test.util.HttpTestCase;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -71,7 +72,7 @@ import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
public class HttpClientTests extends HttpTestCase { public class HttpClientTests extends HttpTestCase {
private TestRepository remoteRepository; private TestRepository<FileRepository> remoteRepository;
private URIish dumbAuthNoneURI; private URIish dumbAuthNoneURI;
@ -95,7 +96,7 @@ public class HttpClientTests extends HttpTestCase {
server.setUp(); server.setUp();
final String srcName = nameOf(remoteRepository); final String srcName = nameOf(remoteRepository.getRepository());
dumbAuthNoneURI = toURIish(dNone, srcName); dumbAuthNoneURI = toURIish(dNone, srcName);
dumbAuthBasicURI = toURIish(dBasic, srcName); dumbAuthBasicURI = toURIish(dBasic, srcName);
@ -119,10 +120,10 @@ public class HttpClientTests extends HttpTestCase {
public Repository open(HttpServletRequest req, String name) public Repository open(HttpServletRequest req, String name)
throws RepositoryNotFoundException, throws RepositoryNotFoundException,
ServiceNotEnabledException { ServiceNotEnabledException {
if (!name.equals(nameOf(remoteRepository))) final FileRepository db = remoteRepository.getRepository();
if (!name.equals(nameOf(db)))
throw new RepositoryNotFoundException(name); throw new RepositoryNotFoundException(name);
final Repository db = remoteRepository.getRepository();
db.incrementOpen(); db.incrementOpen();
return db; return db;
} }
@ -133,8 +134,8 @@ public class HttpClientTests extends HttpTestCase {
return ctx; return ctx;
} }
private static String nameOf(final TestRepository db) { private static String nameOf(final FileRepository db) {
return db.getRepository().getDirectory().getName(); return db.getDirectory().getName();
} }
public void testRepositoryNotFound_Dumb() throws Exception { public void testRepositoryNotFound_Dumb() throws Exception {
@ -198,7 +199,7 @@ public class HttpClientTests extends HttpTestCase {
} }
public void testListRemote_Dumb_NoHEAD() throws Exception { public void testListRemote_Dumb_NoHEAD() throws Exception {
Repository src = remoteRepository.getRepository(); FileRepository src = remoteRepository.getRepository();
File headref = new File(src.getDirectory(), Constants.HEAD); File headref = new File(src.getDirectory(), Constants.HEAD);
assertTrue("HEAD used to be present", headref.delete()); assertTrue("HEAD used to be present", headref.delete());
assertFalse("HEAD is gone", headref.exists()); assertFalse("HEAD is gone", headref.exists());
@ -306,7 +307,7 @@ public class HttpClientTests extends HttpTestCase {
} }
public void testListRemote_Smart_UploadPackDisabled() throws Exception { public void testListRemote_Smart_UploadPackDisabled() throws Exception {
Repository src = remoteRepository.getRepository(); FileRepository src = remoteRepository.getRepository();
src.getConfig().setBoolean("http", null, "uploadpack", false); src.getConfig().setBoolean("http", null, "uploadpack", false);
src.getConfig().save(); src.getConfig().save();

9
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java

@ -77,6 +77,7 @@ import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig; import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
@ -94,7 +95,7 @@ import org.eclipse.jgit.transport.URIish;
public class SmartClientSmartServerTest extends HttpTestCase { public class SmartClientSmartServerTest extends HttpTestCase {
private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding"; private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding";
private Repository remoteRepository; private FileRepository remoteRepository;
private URIish remoteURI; private URIish remoteURI;
@ -107,7 +108,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final TestRepository src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName(); final String srcName = src.getRepository().getDirectory().getName();
ServletContextHandler app = server.addContext("/git"); ServletContextHandler app = server.addContext("/git");
@ -489,10 +490,10 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} }
public void testPush_ChunkedEncoding() throws Exception { public void testPush_ChunkedEncoding() throws Exception {
final TestRepository src = createTestRepository(); final TestRepository<FileRepository> src = createTestRepository();
final RevBlob Q_bin = src.blob(new TestRng("Q").nextBytes(128 * 1024)); final RevBlob Q_bin = src.blob(new TestRng("Q").nextBytes(128 * 1024));
final RevCommit Q = src.commit().add("Q", Q_bin).create(); final RevCommit Q = src.commit().add("Q", Q_bin).create();
final Repository db = src.getRepository(); final FileRepository db = src.getRepository();
final String dstName = Constants.R_HEADS + "new.branch"; final String dstName = Constants.R_HEADS + "new.branch";
Transport t; Transport t;

6
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/util/HttpTestCase.java

@ -57,6 +57,7 @@ import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
@ -82,8 +83,9 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase {
super.tearDown(); super.tearDown();
} }
protected TestRepository createTestRepository() throws Exception { protected TestRepository<FileRepository> createTestRepository()
return new TestRepository(createBareRepository()); throws IOException {
return new TestRepository<FileRepository>(createBareRepository());
} }
protected URIish toURIish(String path) throws URISyntaxException { protected URIish toURIish(String path) throws URISyntaxException {

8
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java

@ -260,7 +260,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException * @throws IOException
* the repository could not be created in the temporary area * the repository could not be created in the temporary area
*/ */
protected Repository createBareRepository() throws IOException { protected FileRepository createBareRepository() throws IOException {
return createRepository(true /* bare */); return createRepository(true /* bare */);
} }
@ -271,7 +271,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException * @throws IOException
* the repository could not be created in the temporary area * the repository could not be created in the temporary area
*/ */
protected Repository createWorkRepository() throws IOException { protected FileRepository createWorkRepository() throws IOException {
return createRepository(false /* not bare */); return createRepository(false /* not bare */);
} }
@ -285,11 +285,11 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException * @throws IOException
* the repository could not be created in the temporary area * the repository could not be created in the temporary area
*/ */
private Repository createRepository(boolean bare) throws IOException { private FileRepository createRepository(boolean bare) throws IOException {
String uniqueId = System.currentTimeMillis() + "_" + (testCount++); String uniqueId = System.currentTimeMillis() + "_" + (testCount++);
String gitdirName = "test" + uniqueId + (bare ? "" : "/") + Constants.DOT_GIT; String gitdirName = "test" + uniqueId + (bare ? "" : "/") + Constants.DOT_GIT;
File gitdir = new File(trash, gitdirName).getCanonicalFile(); File gitdir = new File(trash, gitdirName).getCanonicalFile();
Repository db = new FileRepository(gitdir); FileRepository db = new FileRepository(gitdir);
assertFalse(gitdir.exists()); assertFalse(gitdir.exists());
db.create(); db.create();

102
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -73,10 +73,10 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Commit; import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.LockFile; import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectChecker; import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectDirectory; import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter; import org.eclipse.jgit.lib.ObjectWriter;
@ -99,8 +99,13 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
/** Wrapper to make creating test data easier. */ /**
public class TestRepository { * Wrapper to make creating test data easier.
*
* @param <R>
* type of Repository the test data is stored on.
*/
public class TestRepository<R extends Repository> {
private static final PersonIdent author; private static final PersonIdent author;
private static final PersonIdent committer; private static final PersonIdent committer;
@ -119,7 +124,7 @@ public class TestRepository {
committer = new PersonIdent(cn, ce, now, tz); committer = new PersonIdent(cn, ce, now, tz);
} }
private final Repository db; private final R db;
private final RevWalk pool; private final RevWalk pool;
@ -132,9 +137,9 @@ public class TestRepository {
* *
* @param db * @param db
* the test repository to write into. * the test repository to write into.
* @throws Exception * @throws IOException
*/ */
public TestRepository(Repository db) throws Exception { public TestRepository(R db) throws IOException {
this(db, new RevWalk(db)); this(db, new RevWalk(db));
} }
@ -145,9 +150,9 @@ public class TestRepository {
* the test repository to write into. * the test repository to write into.
* @param rw * @param rw
* the RevObject pool to use for object lookup. * the RevObject pool to use for object lookup.
* @throws Exception * @throws IOException
*/ */
public TestRepository(Repository db, RevWalk rw) throws Exception { public TestRepository(R db, RevWalk rw) throws IOException {
this.db = db; this.db = db;
this.pool = rw; this.pool = rw;
this.writer = new ObjectWriter(db); this.writer = new ObjectWriter(db);
@ -155,7 +160,7 @@ public class TestRepository {
} }
/** @return the repository this helper class operates against. */ /** @return the repository this helper class operates against. */
public Repository getRepository() { public R getRepository() {
return db; return db;
} }
@ -443,25 +448,27 @@ public class TestRepository {
* @throws Exception * @throws Exception
*/ */
public void updateServerInfo() throws Exception { public void updateServerInfo() throws Exception {
final ObjectDatabase odb = db.getObjectDatabase(); if (db instanceof FileRepository) {
if (odb instanceof ObjectDirectory) { final FileRepository fr = (FileRepository) db;
RefWriter rw = new RefWriter(db.getAllRefs().values()) { RefWriter rw = new RefWriter(fr.getAllRefs().values()) {
@Override @Override
protected void writeFile(final String name, final byte[] bin) protected void writeFile(final String name, final byte[] bin)
throws IOException { throws IOException {
TestRepository.this.writeFile(name, bin); File path = new File(fr.getDirectory(), name);
TestRepository.this.writeFile(path, bin);
} }
}; };
rw.writePackedRefs(); rw.writePackedRefs();
rw.writeInfoRefs(); rw.writeInfoRefs();
final StringBuilder w = new StringBuilder(); final StringBuilder w = new StringBuilder();
for (PackFile p : ((ObjectDirectory) odb).getPacks()) { for (PackFile p : fr.getObjectDatabase().getPacks()) {
w.append("P "); w.append("P ");
w.append(p.getPackFile().getName()); w.append(p.getPackFile().getName());
w.append('\n'); w.append('\n');
} }
writeFile("objects/info/packs", Constants.encodeASCII(w.toString())); writeFile(new File(new File(fr.getObjectDatabase().getDirectory(),
"info"), "packs"), Constants.encodeASCII(w.toString()));
} }
} }
@ -563,38 +570,40 @@ public class TestRepository {
* @throws Exception * @throws Exception
*/ */
public void packAndPrune() throws Exception { public void packAndPrune() throws Exception {
final ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase(); if (db.getObjectDatabase() instanceof ObjectDirectory) {
final PackWriter pw = new PackWriter(db, NullProgressMonitor.INSTANCE); ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
PackWriter pw = new PackWriter(db, NullProgressMonitor.INSTANCE);
Set<ObjectId> all = new HashSet<ObjectId>();
for (Ref r : db.getAllRefs().values())
all.add(r.getObjectId());
pw.preparePack(all, Collections.<ObjectId> emptySet());
final ObjectId name = pw.computeName();
OutputStream out;
final File pack = nameFor(odb, name, ".pack"); Set<ObjectId> all = new HashSet<ObjectId>();
out = new BufferedOutputStream(new FileOutputStream(pack)); for (Ref r : db.getAllRefs().values())
try { all.add(r.getObjectId());
pw.writePack(out); pw.preparePack(all, Collections.<ObjectId> emptySet());
} finally {
out.close(); final ObjectId name = pw.computeName();
} OutputStream out;
pack.setReadOnly();
final File pack = nameFor(odb, name, ".pack");
out = new BufferedOutputStream(new FileOutputStream(pack));
try {
pw.writePack(out);
} finally {
out.close();
}
pack.setReadOnly();
final File idx = nameFor(odb, name, ".idx");
out = new BufferedOutputStream(new FileOutputStream(idx));
try {
pw.writeIndex(out);
} finally {
out.close();
}
idx.setReadOnly();
final File idx = nameFor(odb, name, ".idx"); odb.openPack(pack, idx);
out = new BufferedOutputStream(new FileOutputStream(idx)); updateServerInfo();
try { prunePacked(odb);
pw.writeIndex(out);
} finally {
out.close();
} }
idx.setReadOnly();
odb.openPack(pack, idx);
updateServerInfo();
prunePacked(odb);
} }
private void prunePacked(ObjectDirectory odb) { private void prunePacked(ObjectDirectory odb) {
@ -609,9 +618,8 @@ public class TestRepository {
return new File(packdir, "pack-" + name.name() + t); return new File(packdir, "pack-" + name.name() + t);
} }
private void writeFile(final String name, final byte[] bin) private void writeFile(final File p, final byte[] bin) throws IOException,
throws IOException, ObjectWritingException { ObjectWritingException {
final File p = new File(db.getDirectory(), name);
final LockFile lck = new LockFile(p); final LockFile lck = new LockFile(p);
if (!lck.lock()) if (!lck.lock())
throw new ObjectWritingException("Can't write " + p); throw new ObjectWritingException("Can't write " + p);

17
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java

@ -82,6 +82,8 @@ class Clone extends AbstractFetchCommand {
@Argument(index = 1, metaVar = "metaVar_directory") @Argument(index = 1, metaVar = "metaVar_directory")
private String localName; private String localName;
private FileRepository dst;
@Override @Override
protected final boolean requiresRepository() { protected final boolean requiresRepository() {
return false; return false;
@ -103,10 +105,11 @@ class Clone extends AbstractFetchCommand {
if (gitdir == null) if (gitdir == null)
gitdir = new File(localName, Constants.DOT_GIT); gitdir = new File(localName, Constants.DOT_GIT);
db = new FileRepository(gitdir); dst = new FileRepository(gitdir);
db.create(); dst.create();
db.getConfig().setBoolean("core", null, "bare", false); dst.getConfig().setBoolean("core", null, "bare", false);
db.getConfig().save(); dst.getConfig().save();
db = dst;
out.format(CLIText.get().initializedEmptyGitRepositoryIn, gitdir.getAbsolutePath()); out.format(CLIText.get().initializedEmptyGitRepositoryIn, gitdir.getAbsolutePath());
out.println(); out.println();
@ -120,13 +123,13 @@ class Clone extends AbstractFetchCommand {
private void saveRemote(final URIish uri) throws URISyntaxException, private void saveRemote(final URIish uri) throws URISyntaxException,
IOException { IOException {
final RemoteConfig rc = new RemoteConfig(db.getConfig(), remoteName); final RemoteConfig rc = new RemoteConfig(dst.getConfig(), remoteName);
rc.addURI(uri); rc.addURI(uri);
rc.addFetchRefSpec(new RefSpec().setForceUpdate(true) rc.addFetchRefSpec(new RefSpec().setForceUpdate(true)
.setSourceDestination(Constants.R_HEADS + "*", .setSourceDestination(Constants.R_HEADS + "*",
Constants.R_REMOTES + remoteName + "/*")); Constants.R_REMOTES + remoteName + "/*"));
rc.update(db.getConfig()); rc.update(dst.getConfig());
db.getConfig().save(); dst.getConfig().save();
} }
private FetchResult runFetch() throws NotSupportedException, private FetchResult runFetch() throws NotSupportedException,

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java

@ -177,14 +177,14 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
} }
private void setBare(File gitDir, boolean bare) throws IOException { private void setBare(File gitDir, boolean bare) throws IOException {
Repository repo = new FileRepository(gitDir, null); FileRepository repo = new FileRepository(gitDir, null);
repo.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, repo.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_BARE, bare); ConfigConstants.CONFIG_KEY_BARE, bare);
repo.getConfig().save(); repo.getConfig().save();
} }
private void setWorkTree(File gitDir, File workTree) throws IOException { private void setWorkTree(File gitDir, File workTree) throws IOException {
Repository repo = new FileRepository(gitDir, null); FileRepository repo = new FileRepository(gitDir, null);
repo.getConfig() repo.getConfig()
.setString(ConfigConstants.CONFIG_CORE_SECTION, null, .setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_WORKTREE, ConfigConstants.CONFIG_KEY_WORKTREE,

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

@ -102,7 +102,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
} }
/** Test repository, initialized for this test case. */ /** Test repository, initialized for this test case. */
protected Repository db; protected FileRepository db;
/** Working directory of {@link #db}. */ /** Working directory of {@link #db}. */
protected File trash; protected File trash;

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java

@ -159,7 +159,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw"); File workdir = new File(trash.getParentFile(), "rw");
workdir.mkdir(); workdir.mkdir();
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); FileRepository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
repo1initial.getConfig().setString("core", null, "worktree", repo1initial.getConfig().setString("core", null, "worktree",
workdir.getAbsolutePath()); workdir.getAbsolutePath());
@ -184,7 +184,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw"); File workdir = new File(trash.getParentFile(), "rw");
workdir.mkdir(); workdir.mkdir();
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); FileRepository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
repo1initial.getConfig() repo1initial.getConfig()
.setString("core", null, "worktree", "../../rw"); .setString("core", null, "worktree", "../../rw");
@ -321,7 +321,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
} }
public void test007_Open() throws IOException { public void test007_Open() throws IOException {
final Repository db2 = new FileRepository(db.getDirectory()); final FileRepository db2 = new FileRepository(db.getDirectory());
assertEquals(db.getDirectory(), db2.getDirectory()); assertEquals(db.getDirectory(), db2.getDirectory());
assertEquals(db.getObjectsDirectory(), db2.getObjectsDirectory()); assertEquals(db.getObjectsDirectory(), db2.getObjectsDirectory());
assertNotSame(db.getConfig(), db2.getConfig()); assertNotSame(db.getConfig(), db2.getConfig());

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java

@ -47,18 +47,19 @@ import java.util.Date;
import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
/** Support for tests of the {@link RevWalk} class. */ /** Support for tests of the {@link RevWalk} class. */
public abstract class RevWalkTestCase extends RepositoryTestCase { public abstract class RevWalkTestCase extends RepositoryTestCase {
private TestRepository util; private TestRepository<Repository> util;
protected RevWalk rw; protected RevWalk rw;
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
util = new TestRepository(db, createRevWalk()); util = new TestRepository<Repository>(db, createRevWalk());
rw = util.getRevWalk(); rw = util.getRevWalk();
} }

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java

@ -292,7 +292,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
public void testUsingHiddenCommonBlobFails() throws Exception { public void testUsingHiddenCommonBlobFails() throws Exception {
// Try to use the 'b' blob that is hidden. // Try to use the 'b' blob that is hidden.
// //
TestRepository s = new TestRepository(src); TestRepository<Repository> s = new TestRepository<Repository>(src);
RevCommit N = s.commit().parent(B).add("q", s.blob("b")).create(); RevCommit N = s.commit().parent(B).add("q", s.blob("b")).create();
// But don't include it in the pack. // But don't include it in the pack.
@ -333,7 +333,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
public void testUsingUnknownBlobFails() throws Exception { public void testUsingUnknownBlobFails() throws Exception {
// Try to use the 'n' blob that is not on the server. // Try to use the 'n' blob that is not on the server.
// //
TestRepository s = new TestRepository(src); TestRepository<Repository> s = new TestRepository<Repository>(src);
RevBlob n = s.blob("n"); RevBlob n = s.blob("n");
RevCommit N = s.commit().parent(B).add("q", n).create(); RevCommit N = s.commit().parent(B).add("q", n).create();
@ -373,7 +373,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
} }
public void testUsingUnknownTreeFails() throws Exception { public void testUsingUnknownTreeFails() throws Exception {
TestRepository s = new TestRepository(src); TestRepository<Repository> s = new TestRepository<Repository>(src);
RevCommit N = s.commit().parent(B).add("q", s.blob("a")).create(); RevCommit N = s.commit().parent(B).add("q", s.blob("a")).create();
RevTree t = s.parseBody(N).getTree(); RevTree t = s.parseBody(N).getTree();

Loading…
Cancel
Save