2 * Copyright (C) 2007 David Watson <dwatson@mimvista.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 package org
.spearce
.jgit
.lib
;
21 import java
.io
.IOException
;
23 public class IndexDiffTest
extends RepositoryTestCase
{
24 public void testAdded() throws IOException
{
25 GitIndex index
= new GitIndex(db
);
26 writeTrashFile("file1", "file1");
27 writeTrashFile("dir/subfile", "dir/subfile");
28 Tree tree
= new Tree(db
);
30 index
.add(trash
, new File(trash
, "file1"));
31 index
.add(trash
, new File(trash
, "dir/subfile"));
32 IndexDiff diff
= new IndexDiff(tree
, index
);
34 assertEquals(2, diff
.getAdded().size());
35 assertTrue(diff
.getAdded().contains("file1"));
36 assertTrue(diff
.getAdded().contains("dir/subfile"));
37 assertEquals(0, diff
.getChanged().size());
38 assertEquals(0, diff
.getModified().size());
39 assertEquals(0, diff
.getRemoved().size());
42 public void testRemoved() throws IOException
{
43 GitIndex index
= new GitIndex(db
);
44 writeTrashFile("file2", "file2");
45 writeTrashFile("dir/file3", "dir/file3");
47 Tree tree
= new Tree(db
);
48 tree
.addFile("file2");
49 tree
.addFile("dir/file3");
50 assertEquals(2, tree
.memberCount());
51 tree
.findBlobMember("file2").setId(new ObjectId("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"));
52 Tree tree2
= (Tree
) tree
.findTreeMember("dir");
53 tree2
.findBlobMember("file3").setId(new ObjectId("873fb8d667d05436d728c52b1d7a09528e6eb59b"));
54 tree2
.setId(new ObjectWriter(db
).writeTree(tree2
));
55 tree
.setId(new ObjectWriter(db
).writeTree(tree
));
57 IndexDiff diff
= new IndexDiff(tree
, index
);
59 assertEquals(2, diff
.getRemoved().size());
60 assertTrue(diff
.getRemoved().contains("file2"));
61 assertTrue(diff
.getRemoved().contains("dir/file3"));
62 assertEquals(0, diff
.getChanged().size());
63 assertEquals(0, diff
.getModified().size());
64 assertEquals(0, diff
.getAdded().size());
67 public void testModified() throws IOException
{
68 GitIndex index
= new GitIndex(db
);
71 index
.add(trash
, writeTrashFile("file2", "file2"));
72 index
.add(trash
, writeTrashFile("dir/file3", "dir/file3"));
74 writeTrashFile("dir/file3", "changed");
76 Tree tree
= new Tree(db
);
77 tree
.addFile("file2").setId(new ObjectId("0123456789012345678901234567890123456789"));
78 tree
.addFile("dir/file3").setId(new ObjectId("0123456789012345678901234567890123456789"));
79 assertEquals(2, tree
.memberCount());
81 Tree tree2
= (Tree
) tree
.findTreeMember("dir");
82 tree2
.setId(new ObjectWriter(db
).writeTree(tree2
));
83 tree
.setId(new ObjectWriter(db
).writeTree(tree
));
84 IndexDiff diff
= new IndexDiff(tree
, index
);
86 assertEquals(2, diff
.getChanged().size());
87 assertTrue(diff
.getChanged().contains("file2"));
88 assertTrue(diff
.getChanged().contains("dir/file3"));
89 assertEquals(1, diff
.getModified().size());
90 assertTrue(diff
.getModified().contains("dir/file3"));
91 assertEquals(0, diff
.getAdded().size());
92 assertEquals(0, diff
.getRemoved().size());
93 assertEquals(0, diff
.getMissing().size());