Ejemplo n.º 1
0
		/// <exception cref="System.Exception"></exception>
		private ApplyResult Init(string name, bool preExists, bool postExists)
		{
			Git git = new Git(db);
			if (preExists)
			{
				a = new RawText(ReadFile(name + "_PreImage"));
				Write(new FilePath(db.Directory.GetParent(), name), a.GetString(0, a.Size(), false
					));
				git.Add().AddFilepattern(name).Call();
				git.Commit().SetMessage("PreImage").Call();
			}
			if (postExists)
			{
				b = new RawText(ReadFile(name + "_PostImage"));
			}
			return git.Apply().SetPatch(typeof(DiffFormatterReflowTest).GetResourceAsStream(name
				 + ".patch")).Call();
		}
Ejemplo n.º 2
0
        /// <exception cref="System.Exception"></exception>
        private ApplyResult Init(string name, bool preExists, bool postExists)
        {
            Git git = new Git(db);

            if (preExists)
            {
                a = new RawText(ReadFile(name + "_PreImage"));
                Write(new FilePath(db.Directory.GetParent(), name), a.GetString(0, a.Size(), false
                                                                                ));
                git.Add().AddFilepattern(name).Call();
                git.Commit().SetMessage("PreImage").Call();
            }
            if (postExists)
            {
                b = new RawText(ReadFile(name + "_PostImage"));
            }
            return(git.Apply().SetPatch(typeof(DiffFormatterReflowTest).GetResourceAsStream(name
                                                                                            + ".patch")).Call());
        }
Ejemplo n.º 3
0
        /// <exception cref="System.Exception"></exception>
        public ApplyResult Init(string name, bool preExists = true, bool postExists = true)
        {
            Git git = new Git(db);

            if (preExists)
            {
                a = new RawText(ReadFile(name + "_PreImage", useCrlfFiles));
                JGitTestUtil.Write(new FilePath(db.Directory.GetParent(), name), a.GetString(0, a.Size(), false
                                                                                             ));
                git.Add().AddFilepattern(name).Call();
                git.Commit().SetMessage("PreImage").Call();
            }
            if (postExists)
            {
                bool postShouldHaveCrlf = preExists && a.GetLineDelimiter() != null?a.GetLineDelimiter() != "\n" : useCrlfPatches;

                b = new RawText(ReadFile(name + "_PostImage", postShouldHaveCrlf));
            }
            return(git.Apply().SetPatch(typeof(DiffFormatterReflowTest).GetResourceAsStream(name + ".patch", useCrlfPatches)).Call());
        }
Ejemplo n.º 4
0
        public void ApplyingPatchWithInconsistentMacLineEndingsIsSuccessfullyApplied()
        {
            const string pre          = "a\r\r\nb";
            const string post         = "a\r\nb";
            var          git          = new Git(db);
            var          modifiedFile = Path.Combine(db.WorkTree, "file.txt");

            File.WriteAllText(modifiedFile, pre);
            git.Add().AddFilepattern(".").Call();
            git.Commit().SetMessage("Initial commit").Call();

            var patch = GetPatch(modifiedFile, pre, post, git);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(patch)))
            {
                git.Apply().SetPatch(stream).Call();
            }

            Assert.That(File.ReadAllText(modifiedFile), Is.EqualTo(post));
        }