final File repoDir = RepoUtils.initEmptyTempRepo("testWorkingCopyFileAccess");
final Map<String, ?> props = Collections.singletonMap(Internals.CFG_PROPERTY_REVLOG_STREAM_CACHE, false);
repo = new HgLookup(new BasicSessionContext(props, null)).detect(repoDir);
File f1 = new File(repoDir, "file1");
final String c1 = "First", c2 = "Second", c3 = "Third";
ByteArrayChannel ch;
ExecHelper exec = new ExecHelper(new OutputParser.Stub(), repoDir);
// commit cset 0
write(f1, c1);
exec.run("hg", "add");
Assert.assertEquals(0, exec.getExitValue());
exec.run("hg", "commit", "-m", "c0");
Assert.assertEquals(0, exec.getExitValue());
// commit cset 1
write(f1, c2);
exec.run("hg", "commit", "-m", "c1");
assertEquals(0, exec.getExitValue());
//
// modify working copy
write(f1, c3);
//
HgDataFile df = repo.getFileNode(f1.getName());
// 1. Shall take content of the file from the dir
df.workingCopy(ch = new ByteArrayChannel());
assertArrayEquals(c3.getBytes(), ch.toArray());
// 2. Shall supply working copy even if no local file is there
f1.delete();
assertFalse(f1.exists());
df = repo.getFileNode(f1.getName());
df.workingCopy(ch = new ByteArrayChannel());
assertArrayEquals(c2.getBytes(), ch.toArray());
//
// 3. Shall extract revision of the file that corresponds actual parents (from dirstate) not the TIP as it was
exec.run("hg", "update", "-r", "0");
assertEquals(0, exec.getExitValue());
f1.delete();
assertFalse(f1.exists());
// there's no file and workingCopy shall do some extra work to find out actual revision to check out
df = repo.getFileNode(f1.getName());
df.workingCopy(ch = new ByteArrayChannel());
assertArrayEquals(c1.getBytes(), ch.toArray());
}