use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class StagedChangeCacheTest method shouldListTwoWorkspaceDeletions.
@Test
public void shouldListTwoWorkspaceDeletions() throws Exception {
// given
try (Git git = new Git(db)) {
writeTrashFile(db, "a.txt", "trash");
writeTrashFile(db, "b.txt", "trash");
git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
git.commit().setMessage("new commit").call();
git.rm().addFilepattern("a.txt").addFilepattern("b.txt").call();
}
// when
Map<String, Change> result = StagedChangeCache.build(db);
// then
assertThat(result.size(), is(2));
assertFileDeletion(result, "a.txt", "a.txt");
assertFileDeletion(result, "b.txt", "b.txt");
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class StagedChangeCacheTest method shouldListSingleWorkspaceChange.
@Test
public void shouldListSingleWorkspaceChange() throws Exception {
// given
try (Git git = new Git(db)) {
writeTrashFile(db, "a.txt", "trash");
git.add().addFilepattern("a.txt").call();
git.commit().setMessage("initial a.txt commit").call();
writeTrashFile(db, "a.txt", "modification");
git.add().addFilepattern("a.txt").call();
}
// when
Map<String, Change> result = StagedChangeCache.build(db);
// then
assertThat(result.size(), is(1));
assertFileChange(result, "a.txt", "a.txt");
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class WorkingTreeChangeCache method build.
/**
* @param repo
* with should be scanned
* @return list of changes in working tree
*/
public static Map<String, Change> build(Repository repo) {
try (TreeWalk tw = new TreeWalk(repo)) {
int fileNth = tw.addTree(new FileTreeIterator(repo));
int cacheNth = tw.addTree(new DirCacheIterator(repo.readDirCache()));
tw.setFilter(new IndexDiffFilter(cacheNth, fileNth));
tw.setRecursive(true);
Map<String, Change> result = new HashMap<String, Change>();
MutableObjectId idBuf = new MutableObjectId();
while (tw.next()) {
Change change = new Change();
change.name = tw.getNameString();
tw.getObjectId(idBuf, 0);
change.objectId = AbbreviatedObjectId.fromObjectId(idBuf);
tw.getObjectId(idBuf, 1);
change.remoteObjectId = AbbreviatedObjectId.fromObjectId(idBuf);
calculateAndSetChangeKind(RIGHT, change);
result.put(tw.getPathString(), change);
}
return result;
} catch (IOException e) {
Activator.logError(e.getMessage(), e);
return new HashMap<String, GitCommitsModelCache.Change>(0);
}
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class ChangeTest method shouldNotBeEqualWhenOneRemoteObjectIsNull.
@Test
public void shouldNotBeEqualWhenOneRemoteObjectIsNull() {
// given
Change c1 = new Change();
Change c2 = new Change();
c1.objectId = c2.commitId = ZERO_ID;
c1.remoteObjectId = MISC_ID;
// when
boolean result = c1.equals(c2);
// then
assertFalse(result);
assertFalse(c1.hashCode() == c2.hashCode());
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class ChangeTest method shouldBeEqualWhenBothIdsAreNull.
@Test
public void shouldBeEqualWhenBothIdsAreNull() {
// given
Change change = new Change();
// when
boolean result = change.equals(new Change());
// then
assertTrue(result);
}
Aggregations