public void testCacheOpen() { RepositoryCache.FileKey loc = RepositoryCache.FileKey.exact(db.Directory); Core.Repository d2 = RepositoryCache.open(loc); Assert.AreNotSame(db, d2); Assert.AreSame(d2, RepositoryCache.open(RepositoryCache.FileKey.exact(loc.getFile()))); d2.Close(); d2.Close(); }
/// <exception cref="System.IO.IOException"></exception> private FileObjectDatabase.AlternateHandle OpenAlternate(FilePath objdir) { FilePath parent = objdir.GetParentFile(); if (RepositoryCache.FileKey.IsGitRepository(parent, fs)) { RepositoryCache.FileKey key = RepositoryCache.FileKey.Exact(parent, fs); FileRepository db = (FileRepository)RepositoryCache.Open(key); return(new FileObjectDatabase.AlternateRepository(db)); } NGit.Storage.File.ObjectDirectory db_1 = new NGit.Storage.File.ObjectDirectory(config , objdir, null, fs); return(new FileObjectDatabase.AlternateHandle(db_1)); }
public void testFileKeyOpenExisting() { using (Core.Repository r = new RepositoryCache.FileKey(db.Directory).open(true)) { Assert.IsNotNull(r); Assert.AreEqual(db.Directory.FullName, r.Directory.FullName); } using (Core.Repository r = new RepositoryCache.FileKey(db.Directory).open(false)) { Assert.IsNotNull(r); Assert.AreEqual(db.Directory.FullName, r.Directory.FullName); } }
public void testFileKeyOpenNew() { Core.Repository n = createBareRepository(); DirectoryInfo gitdir = n.Directory; n.Close(); recursiveDelete(gitdir); Assert.IsFalse(gitdir.Exists); var e = AssertHelper.Throws <RepositoryNotFoundException>(() => new RepositoryCache.FileKey(gitdir).open(true)); Assert.AreEqual("repository not found: " + gitdir, e.Message); using (Core.Repository o = new RepositoryCache.FileKey(gitdir).open(false)) { Assert.IsNotNull(o); Assert.AreEqual(gitdir.FullName, o.Directory.FullName); Assert.IsFalse(gitdir.Exists); } }
public void testFileKeyOpenNew() { DirectoryInfo gitdir; using (Repository n = createBareRepository()) { gitdir = n.Directory; } recursiveDelete(gitdir); Assert.IsFalse(Directory.Exists(gitdir.FullName)); // changed from gitdir.Exist in order to work around a Mono bug (cf. DirectoryInfoExist() test method below). var e = AssertHelper.Throws <RepositoryNotFoundException>(() => new RepositoryCache.FileKey(gitdir).open(true)); Assert.AreEqual("repository not found: " + gitdir, e.Message); using (Repository o = new RepositoryCache.FileKey(gitdir).open(false)) { Assert.IsNotNull(o); Assert.AreEqual(gitdir.FullName, o.Directory.FullName); Assert.IsFalse(Directory.Exists(gitdir.FullName)); // changed from gitdir.Exist in order to work around a Mono bug (cf. DirectoryInfoExist() test method below). } }
public void testFileKeyOpenNew() { Repository n = createNewEmptyRepo(true); DirectoryInfo gitdir = n.Directory; n.Close(); recursiveDelete(gitdir); Assert.IsFalse(gitdir.Exists); var e = AssertHelper.Throws<RepositoryNotFoundException>(() => new RepositoryCache.FileKey(gitdir).open(true)); Assert.AreEqual("repository not found: " + gitdir, e.Message); Repository o = new RepositoryCache.FileKey(gitdir).open(false); Assert.IsNotNull(o); Assert.AreEqual(gitdir.FullName, o.Directory.FullName); Assert.IsFalse(gitdir.Exists); }
public void testFileKeyOpenExisting() { Repository r = new RepositoryCache.FileKey(db.Directory).open(true); Assert.IsNotNull(r); Assert.AreEqual(db.Directory.FullName, r.Directory.FullName); r.Close(); r = new RepositoryCache.FileKey(db.Directory).open(false); Assert.IsNotNull(r); Assert.AreEqual(db.Directory.FullName, r.Directory.FullName); r.Close(); }
public void testFileKeyOpenNew() { Repository n = createNewEmptyRepo(true); DirectoryInfo gitdir = n.Directory; n.Close(); recursiveDelete(gitdir); Assert.IsFalse(gitdir.Exists); try { new RepositoryCache.FileKey(gitdir).open(true); Assert.Fail("incorrectly opened a non existant repository"); } catch (RepositoryNotFoundException e) { Assert.AreEqual("repository not found: " + gitdir, e.Message); } Repository o = new RepositoryCache.FileKey(gitdir).open(false); Assert.IsNotNull(o); Assert.AreEqual(gitdir.FullName, o.Directory.FullName); Assert.IsFalse(gitdir.Exists); }
/// <exception cref="NGit.Errors.RepositoryNotFoundException"></exception> /// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception> public override Repository Open(C req, string name) { if (IsUnreasonableName(name)) { throw new RepositoryNotFoundException(name); } Repository db = exports.Get(NameWithDotGit(name)); if (db != null) { db.IncrementOpen(); return(db); } foreach (FilePath @base in exportBase) { FilePath dir = RepositoryCache.FileKey.Resolve(new FilePath(@base, name), FS.DETECTED ); if (dir == null) { continue; } try { RepositoryCache.FileKey key = RepositoryCache.FileKey.Exact(dir, FS.DETECTED); db = RepositoryCache.Open(key, true); } catch (IOException e) { throw new RepositoryNotFoundException(name, e); } try { if (IsExportOk(req, name, db)) { // We have to leak the open count to the caller, they // are responsible for closing the repository if we // complete successfully. return(db); } else { throw new ServiceNotEnabledException(); } } catch (RuntimeException e) { db.Close(); throw new RepositoryNotFoundException(name, e); } catch (IOException e) { db.Close(); throw new RepositoryNotFoundException(name, e); } catch (ServiceNotEnabledException e) { db.Close(); throw; } } if (exportBase.Count == 1) { FilePath dir = new FilePath(exportBase.Iterator().Next(), name); throw new RepositoryNotFoundException(name, new RepositoryNotFoundException(dir)); } throw new RepositoryNotFoundException(name); }