/// <exception cref="NGit.Errors.NoWorkTreeException"></exception> /// <exception cref="System.IO.IOException"></exception> private void Checkout() { ObjectReader r = db.ObjectDatabase.NewReader(); try { foreach (KeyValuePair <string, DirCacheEntry> entry in toBeCheckedOut.EntrySet()) { FilePath f = new FilePath(db.WorkTree, entry.Key); CreateDir(f.GetParentFile()); DirCacheCheckout.CheckoutEntry(db, f, entry.Value, r); modifiedFiles.AddItem(entry.Key); } // Iterate in reverse so that "folder/file" is deleted before // "folder". Otherwise this could result in a failing path because // of a non-empty directory, for which delete() would fail. for (int i = toBeDeleted.Count - 1; i >= 0; i--) { string fileName = toBeDeleted[i]; FilePath f = new FilePath(db.WorkTree, fileName); if (!f.Delete()) { failingPaths.Put(fileName, ResolveMerger.MergeFailureReason.COULD_NOT_DELETE); } modifiedFiles.AddItem(fileName); } } finally { r.Release(); } }
public override void Apply(DirCacheEntry ent) { ent.SetObjectId(blobId); ent.FileMode = mode; try { DirCacheCheckout.CheckoutEntry(this._enclosing.repo, new FilePath(workTree, ent.PathString ), ent, r); } catch (IOException e) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().checkoutConflictWithFile , ent.PathString), e); } }
/// <exception cref="System.IO.IOException"></exception> private void ApplyChanges(TreeWalk treeWalk, DirCache cache, DirCacheEditor editor ) { FilePath workingTree = repo.WorkTree; while (treeWalk.Next()) { string path = treeWalk.PathString; FilePath file = new FilePath(workingTree, path); // State of the stashed HEAD, index, and working directory AbstractTreeIterator stashHeadIter = treeWalk.GetTree <AbstractTreeIterator>(0); AbstractTreeIterator stashIndexIter = treeWalk.GetTree <AbstractTreeIterator>(1); AbstractTreeIterator stashWorkingIter = treeWalk.GetTree <AbstractTreeIterator>(2); if (stashWorkingIter != null && stashIndexIter != null) { // Checkout index change DirCacheEntry entry = cache.GetEntry(path); if (entry == null) { entry = new DirCacheEntry(treeWalk.RawPath); } entry.FileMode = stashIndexIter.EntryFileMode; entry.SetObjectId(stashIndexIter.EntryObjectId); DirCacheCheckout.CheckoutEntry(repo, file, entry, treeWalk.ObjectReader); DirCacheEntry updatedEntry = entry; editor.Add(new _PathEdit_270(updatedEntry, path)); // Checkout working directory change if (!stashWorkingIter.IdEqual(stashIndexIter)) { entry = new DirCacheEntry(treeWalk.RawPath); entry.SetObjectId(stashWorkingIter.EntryObjectId); DirCacheCheckout.CheckoutEntry(repo, file, entry, treeWalk.ObjectReader); } } else { if (stashIndexIter == null || (stashHeadIter != null && !stashIndexIter.IdEqual(stashHeadIter ))) { editor.Add(new DirCacheEditor.DeletePath(path)); } FileUtils.Delete(file, FileUtils.RETRY | FileUtils.SKIP_MISSING); } } }
/// <summary>Checkout paths into index and working directory</summary> /// <returns>this instance</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> /// <exception cref="NGit.Api.Errors.RefNotFoundException">NGit.Api.Errors.RefNotFoundException /// </exception> protected internal virtual NGit.Api.CheckoutCommand CheckoutPaths() { RevWalk revWalk = new RevWalk(repo); DirCache dc = repo.LockDirCache(); try { TreeWalk treeWalk = new TreeWalk(revWalk.GetObjectReader()); treeWalk.Recursive = true; treeWalk.AddTree(new DirCacheIterator(dc)); treeWalk.Filter = PathFilterGroup.CreateFromStrings(paths); IList <string> files = new List <string>(); while (treeWalk.Next()) { files.AddItem(treeWalk.PathString); } if (startCommit != null || startPoint != null) { DirCacheEditor editor = dc.Editor(); TreeWalk startWalk = new TreeWalk(revWalk.GetObjectReader()); startWalk.Recursive = true; startWalk.Filter = treeWalk.Filter; startWalk.AddTree(revWalk.ParseCommit(GetStartPoint()).Tree); while (startWalk.Next()) { ObjectId blobId = startWalk.GetObjectId(0); editor.Add(new _PathEdit_258(blobId, startWalk.PathString)); } editor.Commit(); } FilePath workTree = repo.WorkTree; foreach (string file in files) { DirCacheCheckout.CheckoutEntry(repo, new FilePath(workTree, file), dc.GetEntry(file )); } } finally { dc.Unlock(); revWalk.Release(); } return(this); }
/// <exception cref="NGit.Errors.NoWorkTreeException"></exception> /// <exception cref="System.IO.IOException"></exception> private void Checkout() { foreach (KeyValuePair <string, DirCacheEntry> entry in toBeCheckedOut.EntrySet()) { FilePath f = new FilePath(db.WorkTree, entry.Key); if (entry.Value != null) { CreateDir(f.GetParentFile()); DirCacheCheckout.CheckoutEntry(db, f, entry.Value); } else { if (!f.Delete()) { failingPaths.Put(entry.Key, ResolveMerger.MergeFailureReason.COULD_NOT_DELETE); } } modifiedFiles.AddItem(entry.Key); } }
public virtual void TestIsModifiedSymlink() { FilePath f = WriteTrashFile("symlink", "content"); Git git = new Git(db); git.Add().AddFilepattern("symlink").Call(); git.Commit().SetMessage("commit").Call(); // Modify previously committed DirCacheEntry and write it back to disk DirCacheEntry dce = db.ReadDirCache().GetEntry("symlink"); dce.FileMode = FileMode.SYMLINK; DirCacheCheckout.CheckoutEntry(db, f, dce); FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig )db.GetConfig()).Get(WorkingTreeOptions.KEY)); while (!fti.EntryPathString.Equals("symlink")) { fti.Next(1); } NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false)); }
public override void Apply(DirCacheEntry ent) { if (checkoutIndex && ent.Stage > DirCacheEntry.STAGE_0) { UnmergedPathException e = new UnmergedPathException(ent); throw new JGitInternalException(e.Message, e); } ent.SetObjectId(blobId); ent.FileMode = mode; FilePath file = new FilePath(workTree, ent.PathString); FilePath parentDir = file.GetParentFile(); try { FileUtils.Mkdirs(parentDir, true); DirCacheCheckout.CheckoutEntry(this._enclosing.repo, file, ent, r); } catch (IOException e) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().checkoutConflictWithFile , ent.PathString), e); } }