示例#1
0
        public FormCommitDiff(GitUICommands commands, ObjectId objectId)
            : this(commands)
        {
            CommitDiff.TextChanged += (s, e) => Text = CommitDiff.Text;

            CommitDiff.SetRevision(objectId, fileToSelect: null);
        }
示例#2
0
        public async Task TestDiffCommitAsync()
        {
            await git.InitRepoAsync();

            io.WriteFile("file1.txt", "text1");
            io.WriteFile("file2.txt", "text2");
            GitCommit commit1 = await git.CommitAllChangesAsync("Message1");

            io.WriteFile("file1.txt", "text12");
            io.WriteFile("file2.txt", "text22");
            GitCommit commit2 = await git.CommitAllChangesAsync("Message2");

            R <string> result = await cmd.GetCommitDiffAsync(commit1.Sha.Sha, ct);

            Assert.AreEqual(true, result.IsOk);

            CommitDiff diff = await git.ParsePatchAsync(commit1.Sha, result.Value);

            Assert.IsNotNullOrEmpty(diff.LeftText);
            Assert.IsNotNullOrEmpty(diff.RightText);

            result = await cmd.GetCommitDiffAsync(commit2.Sha.Sha, ct);

            Assert.AreEqual(true, result.IsOk);

            CommitDiff diff2 = await git.ParsePatchAsync(commit1.Sha, result.Value);

            Assert.IsNotNullOrEmpty(diff2.LeftText);
            Assert.IsNotNullOrEmpty(diff2.RightText);
        }
示例#3
0
        public async Task TestDiffDeletedFiletAsync()
        {
            GitDiffParser diffParser = new GitDiffParser();

            await git.InitRepoAsync();

            io.WriteFile("file1.txt", "text1");
            GitCommit commit1 = await git.CommitAllChangesAsync("Message1");

            io.DeleteFile("file1.txt");
            GitCommit commit2 = await git.CommitAllChangesAsync("Message2");

            R <string> result1 = await cmd.GetFileDiffAsync(commit1.Sha.Sha, "file1.txt", ct);

            Assert.AreEqual(true, result1.IsOk);

            CommitDiff diff1 = await diffParser.ParseAsync(commit1.Sha, result1.Value, false, false);

            Assert.IsNullOrEmpty(File.ReadAllText(diff1.LeftPath));
            Assert.AreEqual("text1\r\n", File.ReadAllText(diff1.RightPath));

            R <string> result2 = await cmd.GetFileDiffAsync(commit2.Sha.Sha, "file1.txt", ct);

            Assert.AreEqual(true, result2.IsOk);

            CommitDiff diff2 = await diffParser.ParseAsync(commit2.Sha, result2.Value, false, false);

            Assert.AreEqual("text1\r", File.ReadAllText(diff2.LeftPath));
            Assert.IsNullOrEmpty(File.ReadAllText(diff2.RightPath));
        }
示例#4
0
        FileDiff AddFileDiff(CommitDiff commitDiff, string name)
        {
            var result = new FileDiff(FileState.Added, FileType.None, name, null);

            commitDiff.AddFileDiff(result);
            return(result);
        }
示例#5
0
        public async Task ShowFileDiffAsync(CommitSha commitSha, string path)
        {
            string patch;

            if (commitSha == CommitSha.Uncommitted)
            {
                if (!(await gitDiffService.GetUncommittedFileDiffAsync(
                          path, CancellationToken.None)).HasValue(out patch))
                {
                    return;
                }
            }
            else
            {
                if (!(await gitDiffService.GetFileDiffAsync(
                          commitSha.Sha, path, CancellationToken.None)).HasValue(out patch))
                {
                    return;
                }
            }

            CommitDiff commitDiff = await diffParser.ParseAsync(commitSha, patch, false, false);

            await ShowDiffImplAsync(commitDiff.LeftPath, commitDiff.RightPath);
        }
示例#6
0
        public static RevisionDetailViewModel Create(Commit commit, CommitDiff commitDiff, IEnumerable <Comment> comments)
        {
            RevisionDetailViewModel viewModel = new RevisionDetailViewModel()
            {
                RevisedFileDetails =
                    commitDiff.FileDiffs
                    .OrderBy(fd => fd.Name)
                    .Select(fd => new RevisedFileDetailViewModel()
                {
                    Filename    = fd.Name,
                    ModText     = fd.FileState.ToString(),
                    LineDetails = fd.Lines
                                  .Select(ld => new LineDetailViewModel()
                    {
                        Text = ld.Text,
                        RemovedLineNumber = ld.RemovedLineNumber,
                        AddedLineNumber   = ld.AddedLineNumber,
                        ChangeState       = ld.Changed,
                        LineId            = ld.Id,
                        Comments          = comments.Where(comment => MatchesLine(comment, fd, ld))
                                            .Select(comment => CommentViewModel.CreateFrom(comment)).ToList()
                    })
                }
                            )
            };

            viewModel.Revision   = commit.Revision;
            viewModel.Author     = commit.Author;
            viewModel.Message    = commit.Message;
            viewModel.Timestamp  = commit.Timestamp;
            viewModel.ApprovedBy = commit.ApprovedBy;
            viewModel.Reviews    = comments.Where(comment => IsReview(comment)).Select(comment => CommentViewModel.CreateFrom(comment)).ToList();
            return(viewModel);;
        }
示例#7
0
 public async Task ShowPreviewMergeDiffAsync(CommitSha commitSha1, CommitSha commitSha2)
 {
     if ((await gitDiffService.GetPreviewMergeDiffAsync(
              commitSha1.Sha, commitSha2.Sha, CancellationToken.None)).HasValue(out string patch))
     {
         CommitDiff commitDiff = await diffParser.ParseAsync(null, patch, true, false);
         await ShowDiffImplAsync(commitDiff.LeftPath, commitDiff.RightPath);
     }
 }
        public FormCommitDiff([NotNull] GitUICommands commands, [CanBeNull] ObjectId objectId)
            : base(commands)
        {
            InitializeComponent();
            InitializeComplete();

            CommitDiff.TextChanged += (s, e) => Text = CommitDiff.Text;

            CommitDiff.SetRevision(objectId, fileToSelect: null);
        }
示例#9
0
        private void UpdateSelectedFileViewers(bool force = false)
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count == 0)
            {
                return;
            }

            GitRevision revision = selectedRows[0];
            var         children = FileChanges.GetRevisionChildren(revision.Guid);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            SetTitle(fileName);

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding, force: force);
            }
            else if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollpos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevision(fileName, revision.Guid);
                View.ScrollPos = scrollpos;
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                var file = new GitItemStatus
                {
                    IsTracked   = true,
                    Name        = fileName,
                    IsSubmodule = GitModule.IsValidGitWorkingDir(_fullPathResolver.Resolve(fileName))
                };
                Diff.ViewChanges(FileChanges.GetSelectedRevisions(), file, "You need to select at least one revision to view diff.");
            }
            else if (tabControl1.SelectedTab == CommitInfoTabPage)
            {
                CommitDiff.SetRevision(revision.Guid, fileName);
            }

            if (_buildReportTabPageExtension == null)
            {
                _buildReportTabPageExtension = new BuildReportTabPageExtension(tabControl1, _buildReportTabCaption.Text);
            }

            _buildReportTabPageExtension.FillBuildReport(selectedRows.Count == 1 ? revision : null);
        }
示例#10
0
        public void Create_One_FileDiff_No_Likes()
        {
            CommitDiff cd = CreateCommitDiff(0);
            FileDiff   fd = AddFileDiff(cd, "file1");

            AddLineDiff(fd, ChangeState.Added, "line0");
            AddLineDiff(fd, ChangeState.Removed, "line1");

            var result = RevisionDetailViewModel.Create(new Commit(), cd, new Comment[] { });

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.RevisedFileDetails.Count());
            Assert.AreEqual(2, result.RevisedFileDetails.First().LineDetails.Count());
        }
示例#11
0
        public async Task TestDiffUncommittedAsync()
        {
            GitDiffParser diffParser = new GitDiffParser();

            await git.InitRepoAsync();

            io.WriteFile("file1.txt", "line1\nline2\nline3\n");
            io.WriteFile("file2.txt", "line1\nline2\nline3\n");
            await git.CommitAllChangesAsync("Message1");

            io.WriteFile("file1.txt", "line1\nline22\nline3\n");
            io.DeleteFile("file2.txt");
            io.WriteFile("file3.txt", "line1\nline2\nline3\n");

            R <string> result = await cmd.GetUncommittedDiffAsync(ct);

            CommitDiff diff = await diffParser.ParseAsync(null, result.Value, true, false);

            string d1 = File.ReadAllText(diff.LeftPath);
            string d2 = File.ReadAllText(diff.RightPath);

            Assert.IsNotNullOrEmpty(result.Value);

            result = await cmd.GetUncommittedFileDiffAsync("file1.txt", ct);

            Assert.IsNotNullOrEmpty(result.Value);



            //io.WriteFile("file1.txt", "line1\nline22\nline3\n");
            //io.DeleteFile("file2.txt");
            //io.WriteFile("file3.txt", "line1\nline2\nline3\n");

            //result = await cmd.GetUncommittedDiffAsync(ct);
            //Assert.IsNotNullOrEmpty(result.Value);

            result = await cmd.GetUncommittedFileDiffAsync("file1.txt", ct);

            Assert.IsNotNullOrEmpty(result.Value);

            result = await cmd.GetUncommittedFileDiffAsync("file2.txt", ct);

            Assert.IsNotNullOrEmpty(result.Value);

            result = await cmd.GetUncommittedFileDiffAsync("file3.txt", ct);

            Assert.IsNotNullOrEmpty(result.Value);
        }
示例#12
0
        private void UpdateSelectedFileViewers(bool force = false)
        {
            var selectedRevisions = FileChanges.GetSelectedRevisions();

            if (selectedRevisions.Count == 0)
            {
                return;
            }

            GitRevision revision = selectedRevisions[0];
            var         children = FileChanges.GetRevisionChildren(revision.ObjectId);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = FileName;
            }

            SetTitle(fileName);

            if (revision.IsArtificial)
            {
                tabControl1.SelectedTab = DiffTab;

                CommitInfoTabPage.Parent = null;
                BlameTab.Parent          = null;
                ViewTab.Parent           = null;
            }
            else
            {
                if (CommitInfoTabPage.Parent == null)
                {
                    tabControl1.TabPages.Insert(0, CommitInfoTabPage);
                }

                if (ViewTab.Parent == null)
                {
                    var index = tabControl1.TabPages.IndexOf(DiffTab);
                    Debug.Assert(index != -1, "TabControl should contain diff tab page");
                    tabControl1.TabPages.Insert(index + 1, ViewTab);
                }

                if (BlameTab.Parent == null)
                {
                    var index = tabControl1.TabPages.IndexOf(ViewTab);
                    Debug.Assert(index != -1, "TabControl should contain view tab page");
                    tabControl1.TabPages.Insert(index + 1, BlameTab);
                }
            }

            if (tabControl1.SelectedTab == BlameTab)
            {
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding, force: force);
            }
            else if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollPos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevisionAsync(fileName, revision.ObjectId);
                View.ScrollPos = scrollPos;
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                var file = new GitItemStatus
                {
                    IsTracked   = true,
                    Name        = fileName,
                    IsSubmodule = GitModule.IsValidGitWorkingDir(_fullPathResolver.Resolve(fileName))
                };
                Diff.ViewChangesAsync(FileChanges.GetSelectedRevisions(), file, "You need to select at least one revision to view diff.");
            }
            else if (tabControl1.SelectedTab == CommitInfoTabPage)
            {
                CommitDiff.SetRevision(revision.ObjectId, fileName);
            }

            if (_buildReportTabPageExtension == null)
            {
                _buildReportTabPageExtension = new BuildReportTabPageExtension(tabControl1, _buildReportTabCaption.Text);
            }

            _buildReportTabPageExtension.FillBuildReport(selectedRevisions.Count == 1 ? revision : null);
        }
示例#13
0
 bool OnOrAfter(CommitDiff diffs)
 {
     // Datetime may come in in as "unspecified", we need to be sure it's specified
     // to get accurate comparisons to a commit's DateTimeOffset
     return(Analysis.OnOrAfter(DateTime.SpecifyKind(dateFilter.Value, DateTimeKind.Local))(diffs));
 }
示例#14
0
 static bool NoFilter(CommitDiff diffs) => true;
示例#15
0
 public FormCommitDiff(GitUICommands commands, string revisionGuid)
     : this(commands)
 {
     CommitDiff.TextChanged += CommitDiff_TextChanged;
     CommitDiff.SetRevision(revisionGuid, null);
 }
        public async Task TestConflictsResolveAsync()
        {
            GitDiffParser diffParser = new GitDiffParser();

            await git.InitRepoAsync();

            // Add some files as initial add on master
            io.WriteFile("file1.txt", "Text 1");
            io.WriteFile("file2.txt", "Text 2");
            io.WriteFile("file3.txt", "Text 3");
            io.WriteFile("file4.txt", "Text 4");
            io.WriteFile("file5.txt", "Text 5");
            GitCommit masterCommit1 = await git.CommitAllChangesAsync("Initial add on master");

            // Create branch1
            await git.BranchAsync("branch1");

            io.WriteFile("file1.txt", "Text 12 on branch\r\n\n");
            io.DeleteFile("file2.txt");                                       // Deleted 2 on branch
            io.WriteFile("file3.txt", "Text 32 on branch");
            io.WriteFile("file4.txt", "Text 42 on branch");
            io.DeleteFile("file5.txt");                                       // Delete 5 on branch
            io.WriteFile("file6.txt", "Text 62 on branch");                   // Added 6 on branch
            GitCommit branchCommit1 = await git.CommitAllChangesAsync("Message 1 on branch1");

            // Switch to master and make some changes and commit
            await git.CheckoutAsync("master");

            io.WriteFile("file1.txt", "Text 12 on master\n");
            io.WriteFile("file2.txt", "Text 22 on master");
            io.DeleteFile("file3.txt");                                       // Delete 3 on master
            // No change on file 4
            io.DeleteFile("file5.txt");                                       // Delete 5 om master
            io.WriteFile("file6.txt", "Text 62 on master");                   // added on master
            GitCommit masterCommit2 = await git.CommitAllChangesAsync("Message 2 on master");

            // Merge branch to master, expecting 1CMM, 2CMD, 3CDM, 4M, (no 5), 6CAA
            R result = await cmd.MergeAsync("branch1", ct);

            status = await git.GetStatusAsync();

            Assert.AreEqual(1, status.Modified);
            Assert.AreEqual(4, status.Conflicted);
            Assert.AreEqual(true, status.IsMerging);

            GitConflicts conflicts = await git.GetConflictsAsync();

            Assert.AreEqual(true, conflicts.HasConflicts);
            Assert.AreEqual(4, conflicts.Count);


            io.WriteFile("file1.txt", "Text 13 merged");
            status = await git.GetStatusAsync();

            await git.Service <IGitStatusService>().Call(m => m.AddAsync("file1.txt", ct));

            status = await git.GetStatusAsync();

            Assert.AreEqual(2, status.Modified);
            Assert.AreEqual(3, status.Conflicted);

            io.DeleteFile("file2.txt");
            await git.Service <IGitStatusService>().Call(m => m.RemoveAsync("file2.txt", ct));

            status = await git.GetStatusAsync();

            Assert.AreEqual(2, status.Modified);
            Assert.AreEqual(1, status.Deleted);
            Assert.AreEqual(2, status.Conflicted);


            string branchSide = await git.GetConflictFileAsync(conflicts.Files[2].RemoteId);

            io.WriteFile("file3.txt", branchSide);
            await git.Service <IGitStatusService>().Call(m => m.AddAsync("file3.txt", ct));

            status = await git.GetStatusAsync();

            Assert.AreEqual(3, status.Modified);
            Assert.AreEqual(1, status.Deleted);
            Assert.AreEqual(1, status.Conflicted);

            io.WriteFile("file6.txt", "Text 63 merged");
            await git.Service <IGitStatusService>().Call(m => m.AddAsync("file6.txt", ct));

            status = await git.GetStatusAsync();

            Assert.AreEqual(4, status.Modified);
            Assert.AreEqual(1, status.Deleted);
            Assert.AreEqual(0, status.Conflicted);


            GitCommit mergeCommit = await git.CommitAllChangesAsync(status.MergeMessage);

            string mergePatch = await git.Service <IGitDiffService>().Call(m => m.GetCommitDiffAsync(mergeCommit.Sha.Sha, ct));

            string mergePatch2 = await git.Service <IGitDiffService>().Call(
                m => m.GetCommitDiffAsync(mergeCommit.Sha.Sha, ct));

            CommitDiff diff = await diffParser.ParseAsync(mergeCommit.Sha, mergePatch, true, false);

            CommitDiff diff2 = await diffParser.ParseAsync(mergeCommit.Sha, mergePatch2, true, false);

            string left  = File.ReadAllText(diff.LeftPath);
            string right = File.ReadAllText(diff.RightPath);

            string left2  = File.ReadAllText(diff2.LeftPath);
            string right2 = File.ReadAllText(diff2.RightPath);
        }