Exemplo n.º 1
0
        public ViewPatch(GitUICommands aCommands)
            : base(aCommands)
        {
            InitializeComponent(); Translate();

            PatchManager = new PatchManager();
        }
Exemplo n.º 2
0
        public void TestLoadPatch()
        {
            PatchManager manager = new PatchManager();

            PatchApply.Patch expectedPatch = new PatchApply.Patch();
            expectedPatch.Type = PatchApply.Patch.PatchType.ChangeFile;
            expectedPatch.Apply = true;
            expectedPatch.PatchHeader = "diff --git a/thisisatest.txt b/thisisatest.txt";
            expectedPatch.PatchIndex = "index 5e4dce2..5eb1e6f 100644";
            expectedPatch.FileNameA = "thisisatest.txt";
            expectedPatch.FileNameB = "thisisatest.txt";
            expectedPatch.AppendTextLine(expectedPatch.PatchHeader);
            expectedPatch.AppendTextLine(expectedPatch.PatchIndex);
            expectedPatch.AppendTextLine("--- a/thisisatest.txt");
            expectedPatch.AppendTextLine("+++ b/thisisatest.txt");
            expectedPatch.AppendTextLine("@@ -1,2 +1,2 @@");
            expectedPatch.AppendTextLine("iiiiii");
            expectedPatch.AppendTextLine("-asdkjaldskjlaksd");
            expectedPatch.AppendTextLine("+changed again");

            manager.LoadPatch(expectedPatch.Text, false, Encoding.Default);

            PatchApply.Patch createdPatch = manager.Patches.First();
            Assert.AreEqual(expectedPatch.Text, createdPatch.Text);
        }
Exemplo n.º 3
0
        public void TestCorrectlyLoadsTheRightNumberOfDiffsInAPatchFile()
        {
            var manager = new PatchManager();
            var testPatch = Encoding.UTF8.GetString(TestResource.TestPatch);
            manager.LoadPatch(testPatch, false);

            Assert.AreEqual(12, manager.Patches.Count);
        }
Exemplo n.º 4
0
        public void TestCorrectlyLoadsTheRightFilenamesInAPatchFile()
        {
            var manager = new PatchManager();
            var testPatch = Encoding.UTF8.GetString(TestResource.TestPatch);
            manager.LoadPatch(testPatch, false);

            Assert.AreEqual(12, manager.Patches.Select(p => p.FileNameA).Distinct().Count());
            Assert.AreEqual(12, manager.Patches.Select(p => p.FileNameB).Distinct().Count());
        }
Exemplo n.º 5
0
        public void TestCorrectlyLoadsTheRightTypeOfDiffsInAPatchFile()
        {
            var manager = new PatchManager();
            var testPatch = Encoding.UTF8.GetString(TestResource.TestPatch);
            manager.LoadPatch(testPatch, false);

            Assert.IsTrue(manager.Patches.Any(p => p.Type == Patch.PatchType.NewFile));
            Assert.IsTrue(manager.Patches.Any(p => p.Type == Patch.PatchType.ChangeFile));
            Assert.IsTrue(manager.Patches.Any(p => p.Type == Patch.PatchType.DeleteFile));
        }
Exemplo n.º 6
0
        public string GetCombinedDiffContent(GitRevision revisionOfMergeCommit, string filePath,
            string extraArgs, Encoding encoding)
        {
            var cmd = string.Format("diff-tree {4} --no-commit-id {0} {1} {2} -- {3}",
                extraArgs,
                revisionOfMergeCommit.Guid,
                AppSettings.UsePatienceDiffAlgorithm ? "--patience" : "",
                filePath,
                AppSettings.OmitUninterestingDiff ? "--cc" : "-c -p");

            var patchManager = new PatchManager();
            var patch = RunCacheableCmd(AppSettings.GitCommand, cmd, LosslessEncoding);

            if (string.IsNullOrWhiteSpace(patch))
            {
                return "";
            }

            patchManager.LoadPatch(patch, false, encoding);
            return GetPatch(patchManager, filePath, filePath).Text;
        }
Exemplo n.º 7
0
        public static Patch GetSingleDiff(string from, string to, string filter, string extraDiffArguments)
        {
            filter = FixPath(filter);
            from = FixPath(from);
            to = FixPath(to);

            var patchManager = new PatchManager();
            var arguments = string.Format("diff{0} \"{1}\" \"{2}\" -- \"{3}\"", extraDiffArguments, to, from, filter);
            patchManager.LoadPatch(RunCachableCmd(Settings.GitCommand, arguments), false);

            return patchManager.patches.Count > 0 ? patchManager.patches[0] : null;
        }
Exemplo n.º 8
0
        public IList<Patch> GetStashedItems(string stashName)
        {
            var patchManager = new PatchManager();
            patchManager.LoadPatch(RunGitCmd("stash show -p " + stashName, LosslessEncoding), false, FilesEncoding);

            return patchManager.Patches;
        }
Exemplo n.º 9
0
        public Patch GetCurrentChanges(string fileName, string oldFileName, bool staged, string extraDiffArguments, Encoding encoding)
        {
            fileName = string.Concat("\"", FixPath(fileName), "\"");
            if (!string.IsNullOrEmpty(oldFileName))
                oldFileName = string.Concat("\"", FixPath(oldFileName), "\"");

            if (AppSettings.UsePatienceDiffAlgorithm)
                extraDiffArguments = string.Concat(extraDiffArguments, " --patience");

            var args = string.Concat("diff ", extraDiffArguments, " -- ", fileName);
            if (staged)
                args = string.Concat("diff -M -C --cached", extraDiffArguments, " -- ", fileName, " ", oldFileName);

            String result = RunGitCmd(args, LosslessEncoding);
            var patchManager = new PatchManager();
            patchManager.LoadPatch(result, false, encoding);

            return patchManager.Patches.Count > 0 ? patchManager.Patches[patchManager.Patches.Count - 1] : null;
        }
Exemplo n.º 10
0
        public static List<Patch> GetStashedItems(string stashName)
        {
            var patchManager = new PatchManager();
            patchManager.LoadPatch(RunCmd(Settings.GitCommand, "stash show -p " + stashName), false);

            return patchManager.Patches;
        }
Exemplo n.º 11
0
        public static List<Patch> GetDiff(string from, string to, string extraDiffArguments)
        {
            PatchManager patchManager = new PatchManager();
            patchManager.LoadPatch(GitCommands.RunCachableCmd(Settings.GitCommand, "diff" + extraDiffArguments + " \"" + from + "\" \"" + to + "\""), false);

            return patchManager.patches;
        }
Exemplo n.º 12
0
        public List<Patch> GetStashedItems(string stashName)
        {
            var patchManager = new PatchManager();
            patchManager.LoadPatch(RunGitCmd("stash show -p " + stashName), false);

            return patchManager.Patches;
        }
 public void GetMD5Hash_AString_ReturnsMD5ForString()
 {
     var pm = new PatchManager();
     var res = pm.GetMD5Hash("hello world");
     Assert.AreEqual("5eb63bbbe01eeed093cb22bb8f5acdc3", res);
 }
Exemplo n.º 14
0
        private void Clear()
        {
            CurrentPatch = null;

            patchManager = new PatchManager();

            GridChangedFiles.DataSource = null;

            PatchedFileEdit.Text = "";
            PatchedFileEdit.Refresh();

            FileToPatchEdit.Text = "";
            FileToPatchEdit.Refresh();

            ChangesList.Text = "";
        }
Exemplo n.º 15
0
 public void TestPatchManagerConstructor()
 {
     PatchManager manager = new PatchManager();
     Assert.IsNotNull(manager);
 }
Exemplo n.º 16
0
        public Patch GetSingleDiff(string @from, string to, string fileName, string oldFileName, string extraDiffArguments, Encoding encoding, bool cacheResult)
        {
            if (!string.IsNullOrEmpty(fileName))
            {
                fileName = fileName.ToPosixPath();
            }
            if (!string.IsNullOrEmpty(oldFileName))
            {
                oldFileName = oldFileName.ToPosixPath();
            }

            //fix refs slashes
            from = from.ToPosixPath();
            to = to.ToPosixPath();
            string commitRange = string.Empty;
            if (!to.IsNullOrEmpty())
                commitRange = "\"" + to + "\"";
            if (!from.IsNullOrEmpty())
                commitRange = string.Join(" ", commitRange, "\"" + from + "\"");

            if (AppSettings.UsePatienceDiffAlgorithm)
                extraDiffArguments = string.Concat(extraDiffArguments, " --patience");

            var patchManager = new PatchManager();
            var arguments = String.Format("diff {0} -M -C {1} -- {2} {3}", extraDiffArguments, commitRange,
                fileName.Quote(), oldFileName.Quote());
            string patch;
            if (cacheResult)
                patch = RunCacheableCmd(AppSettings.GitCommand, arguments, LosslessEncoding);
            else
                patch = RunCmd(AppSettings.GitCommand, arguments, LosslessEncoding);
            patchManager.LoadPatch(patch, false, encoding);

            return GetPatch(patchManager, fileName, oldFileName);
        }
Exemplo n.º 17
0
        public static Patch GetSingleDiff(string from, string to, string filter, string extraDiffArguments)
        {
            filter = FixPath(filter);
            from = FixPath(from);
            to = FixPath(to);

            PatchManager patchManager = new PatchManager();
            patchManager.LoadPatch(GitCommands.RunCachableCmd(Settings.GitCommand, "diff" + extraDiffArguments + " \"" + to + "\" \"" + from + "\" -- \"" + filter + "\""), false);

            if (patchManager.patches.Count > 0)
                return patchManager.patches[0];

            return null;
        }
Exemplo n.º 18
0
        public ViewPatch()
        {
            InitializeComponent(); Translate();

            PatchManager = new PatchManager();
        }
Exemplo n.º 19
0
        public static Patch GetSingleDiff(string from, string to, string fileName, string oldFileName, string extraDiffArguments)
        {
            if (!string.IsNullOrEmpty(fileName))
                fileName = string.Concat("\"", FixPath(fileName), "\"");

            if (!string.IsNullOrEmpty(oldFileName))
                oldFileName = string.Concat("\"", FixPath(oldFileName), "\"");

            from = FixPath(from);
            to = FixPath(to);

            if (Settings.UsePatienceDiffAlgorithm)
                extraDiffArguments = string.Concat(extraDiffArguments, " --patience");

            var patchManager = new PatchManager();
            var arguments = string.Format("diff{0} -M -C \"{1}\" \"{2}\" -- {3} {4}", extraDiffArguments, to, from, fileName, oldFileName);
            patchManager.LoadPatch(RunCachableCmd(Settings.GitCommand, arguments), false);

            return patchManager.Patches.Count > 0 ? patchManager.Patches[0] : null;
        }
Exemplo n.º 20
0
        public Patch GetSingleDiff(string @from, string to, string fileName, string oldFileName, string extraDiffArguments, Encoding encoding)
        {
            if (!string.IsNullOrEmpty(fileName))
                fileName = string.Concat("\"", FixPath(fileName), "\"");

            if (!string.IsNullOrEmpty(oldFileName))
                oldFileName = string.Concat("\"", FixPath(oldFileName), "\"");

            from = FixPath(from);
            to = FixPath(to);
            string commitRange = string.Empty;
            if (!to.IsNullOrEmpty())
                commitRange = "\"" + to + "\"";
            if (!from.IsNullOrEmpty())
                commitRange = commitRange.Join(" ", "\"" + from + "\"");

            if (Settings.UsePatienceDiffAlgorithm)
                extraDiffArguments = string.Concat(extraDiffArguments, " --patience");

            var patchManager = new PatchManager();
            var arguments = string.Format("diff {0} -M -C {1} -- {2} {3}", extraDiffArguments, commitRange, fileName, oldFileName);
            patchManager.LoadPatch(this.RunCachableCmd(Settings.GitCommand, arguments, Settings.LosslessEncoding), false, encoding);

            return patchManager.Patches.Count > 0 ? patchManager.Patches[patchManager.Patches.Count - 1] : null;
        }
Exemplo n.º 21
0
        public static List<Patch> GetDiff(string from, string to, string extraDiffArguments)
        {
            if (Settings.UsePatienceDiffAlgorithm)
                extraDiffArguments = string.Concat(extraDiffArguments, " --patience");

            var patchManager = new PatchManager();
            var arguments = string.Format("diff{0} \"{1}\" \"{2}\"", extraDiffArguments, from, to);
            patchManager.LoadPatch(RunCachableCmd(Settings.GitCommand, arguments), false);

            return patchManager.Patches;
        }
Exemplo n.º 22
0
        public static List<Patch> GetStashedItems(string stashName)
        {
            PatchManager patchManager = new PatchManager();
            patchManager.LoadPatch(GitCommands.RunCmd(Settings.GitDir + "git.cmd", "stash show -p " + stashName), false);

            return patchManager.patches;
        }
Exemplo n.º 23
0
        public Patch GetSingleDiff(string @from, string to, string fileName, string oldFileName, string extraDiffArguments, Encoding encoding, bool cacheResult)
        {
            string fileA = null;
            string fileB = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                fileB = fileName;
                fileName = string.Concat("\"", FixPath(fileName), "\"");
            }

            if (!string.IsNullOrEmpty(oldFileName))
            {
                fileA = oldFileName;
                oldFileName = string.Concat("\"", FixPath(oldFileName), "\"");
            }

            if (fileA.IsNullOrEmpty())
                fileA = fileB;
            else if (fileB.IsNullOrEmpty())
                fileB = fileA;

            from = FixPath(from);
            to = FixPath(to);
            string commitRange = string.Empty;
            if (!to.IsNullOrEmpty())
                commitRange = "\"" + to + "\"";
            if (!from.IsNullOrEmpty())
                commitRange = string.Join(" ", commitRange, "\"" + from + "\"");

            if (AppSettings.UsePatienceDiffAlgorithm)
                extraDiffArguments = string.Concat(extraDiffArguments, " --patience");

            var patchManager = new PatchManager();
            var arguments = String.Format("diff {0} -M -C {1} -- {2} {3}", extraDiffArguments, commitRange, fileName, oldFileName);
            string patch;
            if (cacheResult)
                patch = RunCacheableCmd(AppSettings.GitCommand, arguments, LosslessEncoding);
            else
                patch = RunCmd(AppSettings.GitCommand, arguments, LosslessEncoding);
            patchManager.LoadPatch(patch, false, encoding);

            foreach (Patch p in patchManager.Patches)
                if (p.FileNameA.Equals(fileA) && p.FileNameB.Equals(fileB) ||
                    p.FileNameA.Equals(fileB) && p.FileNameB.Equals(fileA))
                    return p;

            return patchManager.Patches.Count > 0 ? patchManager.Patches[patchManager.Patches.Count - 1] : null;
        }
Exemplo n.º 24
0
        public static List<Patch> GetDiff(string from, string to)
        {
            PatchManager patchManager = new PatchManager();
            patchManager.LoadPatch(GitCommands.RunCmd(Settings.GitDir + "git.cmd", "diff \"" + from + "\" \"" + to + "\""), false);

            return patchManager.patches;
        }
Exemplo n.º 25
0
        public ViewPatch()
        {
            InitializeComponent();

            patchManager = new PatchManager();
        }
Exemplo n.º 26
0
        public static Patch GetSingleDiff(string from, string to, string filter)
        {
            filter = FixPath(filter);
            from = FixPath(from);
            to = FixPath(to);

            PatchManager patchManager = new PatchManager();
            patchManager.LoadPatch(GitCommands.RunCmd(Settings.GitDir + "git.cmd", "diff --ignore-submodules \"" + to + "\" \"" + from + "\" -- \"" + filter + "\""), false);

            if (patchManager.patches.Count > 0)
                return patchManager.patches[0];

            return null;
        }