public WorkerTest() { URIish fetchUrl = new URIish(); SyncableRepository pushRepository = mock(SyncableRepository.class); when(config.getFetchUrl()).thenReturn(fetchUrl); when(config.getPushRepository()).thenReturn(pushRepository); ObjectDatabase database = mock(ObjectDatabase.class); when(database.exists()).thenReturn(false); Repository repository = mock(Repository.class); when(repository.getObjectDatabase()).thenReturn(database); when(config.getWorkingFileRepository()).thenReturn(repository); uut = new Worker(config); }
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException { DirCacheBuilder builder = cache.builder(); DirCacheBuildIterator dci = new DirCacheBuildIterator(builder); TreeWalk walk = new TreeWalk(getRepository()); ObjectDatabase od = null; DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum( ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, DiffAlgorithm.SupportedAlgorithm.HISTOGRAM); MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg)); try { od = getRepository().getObjectDatabase(); walk.addTree(dci); walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts))); String lastPath = null; DirCacheEntry[] entries = new DirCacheEntry[3]; walk.setRecursive(true); while (walk.next()) { DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry(); String path = e.getPathString(); if (lastPath != null && !lastPath.equals(path)) { resolveEntries(merger, lastPath, entries, od, builder); } if (e.getStage() == 0) { DirCacheIterator c = walk.getTree(0, DirCacheIterator.class); builder.add(c.getDirCacheEntry()); } else { entries[e.getStage() - 1] = e; lastPath = path; } } resolveEntries(merger, lastPath, entries, od, builder); builder.commit(); } catch (IOException ex) { throw new GitException(ex); } finally { walk.release(); if (od != null) { od.close(); } } }
public static RawText getRawText (ObjectId id, ObjectDatabase db) throws IOException { if (id.equals(ObjectId.zeroId())) { return RawText.EMPTY_TEXT; } return new RawText(db.open(id, Constants.OBJ_BLOB).getCachedBytes()); }
ObjectDatabase getObjectDatabase() { if (objectDatabase == null) { objectDatabase = repository.getObjectDatabase(); } return objectDatabase; }