comparison test/org/tmatesoft/hg/test/TestCommit.java @ 539:9edfd5a223b8

Commit: handle empty repository case
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 13 Feb 2013 18:44:58 +0100
parents dd4f6311af52
children 6ca3d0c5b4bc
comparison
equal deleted inserted replaced
538:dd4f6311af52 539:9edfd5a223b8
13 * For information on how to redistribute this software under 13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
18 20
19 import java.io.File; 21 import java.io.File;
20 import java.io.FileWriter; 22 import java.io.FileWriter;
21 import java.nio.ByteBuffer; 23 import java.nio.ByteBuffer;
22 24
39 fw.write("hello"); 41 fw.write("hello");
40 fw.close(); 42 fw.close();
41 new ExecHelper(new OutputParser.Stub(true), repoLoc).run("hg", "commit", "--addremove", "-m", "FIRST"); 43 new ExecHelper(new OutputParser.Stub(true), repoLoc).run("hg", "commit", "--addremove", "-m", "FIRST");
42 // 44 //
43 HgRepository hgRepo = new HgLookup().detect(repoLoc); 45 HgRepository hgRepo = new HgLookup().detect(repoLoc);
44 CommitFacility cf = new CommitFacility(hgRepo, 0 /*NO_REVISION*/); 46 CommitFacility cf = new CommitFacility(hgRepo, 0);
47 // FIXME test diff for processing changed newlines - if a whole line or just changed endings are in the patch!
48 cf.add(hgRepo.getFileNode("file1"), new ByteArraySupplier("hello\nworld".getBytes()));
49 cf.commit("SECOND");
50 // /tmp/test-commit2non-empty/.hg/ store/data/file1.i dumpData
51 }
52
53 @Test
54 public void testCommitToEmpty() throws Exception {
55 File repoLoc = RepoUtils.initEmptyTempRepo("test-commit2empty");
56 FileWriter fw = new FileWriter(new File(repoLoc, "file1"));
57 fw.write("hello");
58 fw.close();
59 //
60 HgRepository hgRepo = new HgLookup().detect(repoLoc);
61 CommitFacility cf = new CommitFacility(hgRepo, NO_REVISION);
45 // FIXME test diff for processing changed newlines - if a whole line or just changed endings are in the patch! 62 // FIXME test diff for processing changed newlines - if a whole line or just changed endings are in the patch!
46 cf.add(hgRepo.getFileNode("file1"), new ByteArraySupplier("hello\nworld".getBytes())); 63 cf.add(hgRepo.getFileNode("file1"), new ByteArraySupplier("hello\nworld".getBytes()));
47 cf.commit("commit 1"); 64 cf.commit("commit 1");
48 // /tmp/test-commit2non-empty/.hg/ store/data/file1.i dumpData
49 } 65 }
50 66
51 public static void main(String[] args) throws Exception { 67 public static void main(String[] args) throws Exception {
52 new TestCommit().testCommitToNonEmpty(); 68 new TestCommit().testCommitToEmpty();
69 if (Boolean.TRUE.booleanValue()) {
70 return;
71 }
53 String input = "abcdefghijklmnopqrstuvwxyz"; 72 String input = "abcdefghijklmnopqrstuvwxyz";
54 ByteArraySupplier bas = new ByteArraySupplier(input.getBytes()); 73 ByteArraySupplier bas = new ByteArraySupplier(input.getBytes());
55 ByteBuffer bb = ByteBuffer.allocate(7); 74 ByteBuffer bb = ByteBuffer.allocate(7);
56 byte[] result = new byte[26]; 75 byte[] result = new byte[26];
57 int rpos = 0; 76 int rpos = 0;