/// <exception cref="System.IO.IOException"></exception> private NGit.Patch.Patch ParseTestPatchFile() { using (var @in = GetResourceStream()) { NGit.Patch.Patch p = new NGit.Patch.Patch(); p.Parse(@in); return(p); } }
/// <exception cref="System.IO.IOException"></exception> private NGit.Patch.Patch ParseTestPatchFile(string patchFile) { InputStream @in = GetType().GetResourceAsStream(patchFile); if (@in == null) { NUnit.Framework.Assert.Fail("No " + patchFile + " test vector"); return(null); } // Never happens try { NGit.Patch.Patch p = new NGit.Patch.Patch(); p.Parse(@in); return(p); } finally { @in.Close(); } }
/// <exception cref="System.IO.IOException"></exception> private NGit.Patch.Patch ParseTestPatchFile(string patchFile) { InputStream @in = GetType().GetResourceAsStream(patchFile); if (@in == null) { NUnit.Framework.Assert.Fail("No " + patchFile + " test vector"); return null; } // Never happens try { NGit.Patch.Patch p = new NGit.Patch.Patch(); p.Parse(@in); return p; } finally { @in.Close(); } }
/// <summary> /// Executes the /// <code>ApplyCommand</code> /// command with all the options and /// parameters collected by the setter methods (e.g. /// <see cref="SetPatch(Sharpen.InputStream)">SetPatch(Sharpen.InputStream)</see> /// of this class. Each instance of this class /// should only be used for one invocation of the command. Don't call this /// method twice on an instance. /// </summary> /// <returns> /// an /// <see cref="ApplyResult">ApplyResult</see> /// object representing the command result /// </returns> /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException /// </exception> /// <exception cref="NGit.Api.Errors.PatchFormatException">NGit.Api.Errors.PatchFormatException /// </exception> /// <exception cref="NGit.Api.Errors.PatchApplyException">NGit.Api.Errors.PatchApplyException /// </exception> public override ApplyResult Call() { CheckCallable(); ApplyResult r = new ApplyResult(); try { NGit.Patch.Patch p = new NGit.Patch.Patch(); try { p.Parse(@in); } finally { @in.Close(); } if (!p.GetErrors().IsEmpty()) { throw new PatchFormatException(p.GetErrors()); } foreach (FileHeader fh in p.GetFiles()) { DiffEntry.ChangeType type = fh.GetChangeType(); FilePath f = null; switch (type) { case DiffEntry.ChangeType.ADD: { f = GetFile(fh.GetNewPath(), true); Apply(f, fh); break; } case DiffEntry.ChangeType.MODIFY: { f = GetFile(fh.GetOldPath(), false); Apply(f, fh); break; } case DiffEntry.ChangeType.DELETE: { f = GetFile(fh.GetOldPath(), false); if (!f.Delete()) { throw new PatchApplyException(MessageFormat.Format(JGitText.Get().cannotDeleteFile , f)); } break; } case DiffEntry.ChangeType.RENAME: { f = GetFile(fh.GetOldPath(), false); FilePath dest = GetFile(fh.GetNewPath(), false); if (!f.RenameTo(dest)) { throw new PatchApplyException(MessageFormat.Format(JGitText.Get().renameFileFailed , f, dest)); } break; } case DiffEntry.ChangeType.COPY: { f = GetFile(fh.GetOldPath(), false); byte[] bs = IOUtil.ReadFully(f); FileWriter fw = new FileWriter(GetFile(fh.GetNewPath(), true)); fw.Write(Sharpen.Runtime.GetStringForBytes(bs)); fw.Close(); break; } } r.AddUpdatedFile(f); } } catch (IOException e) { throw new PatchApplyException(MessageFormat.Format(JGitText.Get().patchApplyException , e.Message), e); } SetCallable(false); return(r); }
private static Patch Parse(InputStream crlfStream) { NGit.Patch.Patch p = new Patch(); p.Parse(crlfStream); return(p); }