public void testBuildEmpty() { DirCache dc = DirCache.Lock(db); DirCacheBuilder b = dc.builder(); Assert.IsNotNull(b); b.finish(); dc.write(); Assert.IsTrue(dc.commit()); dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); }
public void testBuildOneFile_FinishWriteCommit() { string path = "a-File-path"; var mode = FileMode.RegularFile; long lastModified = 1218123387057L; int Length = 1342; DirCacheEntry entOrig; DirCache dc = DirCache.Lock(db); DirCacheBuilder b = dc.builder(); Assert.IsNotNull(b); entOrig = new DirCacheEntry(path); entOrig.setFileMode(mode); entOrig.setLastModified(lastModified); entOrig.setLength(Length); Assert.AreNotSame(path, entOrig.getPathString()); Assert.AreEqual(path, entOrig.getPathString()); Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId()); Assert.AreEqual(mode.Bits, entOrig.getRawMode()); Assert.AreEqual(0, entOrig.getStage()); Assert.AreEqual(lastModified, entOrig.getLastModified()); Assert.AreEqual(Length, entOrig.getLength()); Assert.IsFalse(entOrig.isAssumeValid()); b.add(entOrig); b.finish(); Assert.AreEqual(1, dc.getEntryCount()); Assert.AreSame(entOrig, dc.getEntry(0)); dc.write(); Assert.IsTrue(dc.commit()); dc = DirCache.read(db); Assert.AreEqual(1, dc.getEntryCount()); DirCacheEntry entRead = dc.getEntry(0); Assert.AreNotSame(entOrig, entRead); Assert.AreEqual(path, entRead.getPathString()); Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId()); Assert.AreEqual(mode.Bits, entOrig.getRawMode()); Assert.AreEqual(0, entOrig.getStage()); Assert.AreEqual(lastModified, entOrig.getLastModified()); Assert.AreEqual(Length, entOrig.getLength()); Assert.IsFalse(entOrig.isAssumeValid()); }
public void testWriteEmptyReadEmpty_RealIndex() { var idx = new FileInfo(db.Directory + "/index"); var lck = new FileInfo(db.Directory + "/index.lock"); Assert.IsFalse(File.Exists(idx.FullName)); Assert.IsFalse(File.Exists(lck.FullName)); DirCache dc = DirCache.Lock(db); dc.write(); Assert.IsTrue(dc.commit()); Assert.IsTrue(File.Exists(idx.FullName)); dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); }
public void testWriteEmptyCommit_RealIndex() { var idx = new FileInfo(db.Directory + "/index"); var lck = new FileInfo(db.Directory + "/index.lock"); Assert.IsFalse(File.Exists(idx.FullName)); Assert.IsFalse(File.Exists(lck.FullName)); DirCache dc = DirCache.Lock(db); Assert.AreEqual(0, lck.Length); dc.write(); Assert.AreEqual(12 + 20, new FileInfo(lck.FullName).Length); Assert.IsTrue(dc.commit()); Assert.IsTrue(File.Exists(idx.FullName)); Assert.IsFalse(File.Exists(lck.FullName)); Assert.AreEqual(12 + 20, new FileInfo(idx.FullName).Length); }
internal void Apply(Stash stash) { Commit wip = _repo.Get <Commit> (stash.CommitId); Commit index = wip.Parents.Last(); Tree wipTree = wip.Tree; Tree headTree = _repo.CurrentBranch.CurrentCommit.Tree; GitIndex currentIndex = _repo.Index.GitIndex; Tree currentIndexTree = new Tree(_repo, _repo._internal_repo.MapTree(currentIndex.writeTree())); WorkDirCheckout co = new WorkDirCheckout(_repo._internal_repo, _repo._internal_repo.WorkingDirectory, headTree.InternalTree, currentIndex, wip.Tree.InternalTree); co.checkout(); currentIndex.write(); List <DirCacheEntry> toAdd = new List <DirCacheEntry> (); DirCache dc = DirCache.Lock(_repo._internal_repo); try { var cacheEditor = dc.editor(); // The WorkDirCheckout class doesn't check if there are conflicts in modified files, // so we have to do it here. foreach (var c in co.Updated) { var baseEntry = wip.Parents.First().Tree[c.Key] as Leaf; var oursEntry = wipTree [c.Key] as Leaf; var theirsEntry = headTree [c.Key] as Leaf; if (baseEntry != null && oursEntry != null && currentIndexTree [c.Key] == null) { // If a file was reported as updated but that file is not present in the stashed index, // it means that the file was scheduled to be deleted. cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key)); File.Delete(_repo.FromGitPath(c.Key)); } else if (baseEntry != null && oursEntry != null && theirsEntry != null) { MergeResult res = MergeAlgorithm.merge(new RawText(baseEntry.RawData), new RawText(oursEntry.RawData), new RawText(theirsEntry.RawData)); MergeFormatter f = new MergeFormatter(); using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(_repo.FromGitPath(c.Key)))) { f.formatMerge(bw, res, "Base", "Stash", "Head", Constants.CHARSET.WebName); } if (res.containsConflicts()) { // Remove the entry from the index. It will be added later on. cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key)); // Generate index entries for each merge stage // Those entries can't be added right now to the index because a DirCacheEditor // can't be used at the same time as a DirCacheBuilder. var e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_1); e.setObjectId(baseEntry.InternalEntry.Id); e.setFileMode(baseEntry.InternalEntry.Mode); toAdd.Add(e); e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_2); e.setObjectId(oursEntry.InternalEntry.Id); e.setFileMode(oursEntry.InternalEntry.Mode); toAdd.Add(e); e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_3); e.setObjectId(theirsEntry.InternalEntry.Id); e.setFileMode(theirsEntry.InternalEntry.Mode); toAdd.Add(e); } } } cacheEditor.finish(); if (toAdd.Count > 0) { // Add the index entries generated above var cacheBuilder = dc.builder(); for (int n = 0; n < dc.getEntryCount(); n++) { cacheBuilder.@add(dc.getEntry(n)); } foreach (var entry in toAdd) { cacheBuilder.@add(entry); } cacheBuilder.finish(); } dc.write(); dc.commit(); } catch { dc.unlock(); throw; } }