8000 Update to use modern version of LibGit2Sharp and use indent heuristic when diffing by jcansdale · Pull Request #2142 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Update to use modern version of LibGit2Sharp and use indent heuristic when diffing #2142

Merged
merged 26 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e8d9527
Update to be compatible with LigGit2Sharp 0.26
jcansdale Dec 18, 2018
4658122
Fix tests that use LibGit2Sharp
jcansdale Dec 18, 2018
b0c037b
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Dec 18, 2018
8b6a488
Remove obsolete IQueryableCommitLog.QueryBy imple
jcansdale Dec 18, 2018
32c4aac
Update to use LibGit2Sharp 0.26.0-preview-0080
jcansdale Dec 18, 2018
bbc0504
Commit[] no longer accepts \ in path
jcansdale Dec 19, 2018
128cfbe
Remove unused defaultOriginName field
jcansdale Jan 7, 2019
057844a
Enable IndentHeuristic when comparing
jcansdale Jan 8, 2019
62ccc9b
Move Compare and CompareWith to IGitService
jcansdale Jan 8, 2019
e6ebab6
Add failing Indent_Heuristic_Is_Enabled test
jcansdale Jan 8, 2019
e0eb92c
Add tests for GitService.CompareWith
jcansdale Jan 8, 2019
c222de2
Enable IndentHeuristic and make tests pass
jcansdale Jan 8, 2019
d95149d
Move IGitClient.Compare method to IGitService
jcansdale Jan 8, 2019
df677af
Add test for Compare that returns TreeChanges
jcansdale Jan 8, 2019
ca6de27
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Jan 9, 2019
b348527
Add failing test for GitService.Compare
jcansdale Jan 9, 2019
cc43965
Change to use / separator for Git path
jcansdale Jan 9, 2019
7362f56
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Jan 9, 2019
f685a22
Throw ArgumentException if path contains \
jcansdale Jan 9, 2019
346bfe1
Factor out Guard.ArgumentIsGitPath
jcansdale Jan 9, 2019
7d87a40
Add Guard.ArgumentIsGitPath to appropriate methods
jcansdale Jan 9, 2019
7006897
Fix issue where a Windows path is being used
jcansdale Jan 9, 2019
8c5d1f7
Add guards to HasChangesInWorkingDirectory
jcansdale Jan 9, 2019
6fa16e8
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Mar 19, 2019
f9c9cce
Updatre to use LibGit2Sharp 0.26.0 final
jcansdale Mar 19, 2019
f14b646
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Mar 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Throw ArgumentException if path contains \
Check that path doesn't contain \ rather than automatically convert to
use /.
  • Loading branch information
jcansdale committed Jan 9, 2019
commit f685a22d3831ffd6e88c5966850630d9ff9f877b
7 changes: 5 additions & 2 deletions src/GitHub.Exports/Services/GitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,18 @@ public Task<ContentChanges> CompareWith(IRepository repository, string sha1, str
Guard.ArgumentNotEmptyString(sha1, nameof(sha1));
Guard.ArgumentNotEmptyString(sha2, nameof(sha1));
Guard.ArgumentNotEmptyString(path, nameof(path));
if (path.Contains('\\'))
{
throw new ArgumentException($"The value for '{nameof(path)}' must use '/' not '\\' as directory separator", nameof(path));
}

return Task.Run(() =>
{
var commit1 = repository.Lookup<Commit>(sha1);
var commit2 = repository.Lookup<Commit>(sha2);

var treeChanges = repository.Diff.Compare<TreeChanges>(commit1.Tree, commit2.Tree, defaultCompareOptions);
var normalizedPath = path.Replace("\\", "/");
var change = treeChanges.FirstOrDefault(x => x.Path == normalizedPath);
var change = treeChanges.FirstOrDefault(x => x.Path == path);
var oldPath = change?.OldPath;

if (commit1 != null && oldPath != null)
Expand Down
3 changes: 2 additions & 1 deletion src/GitHub.Exports/Services/IGitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ public interface IGitService
/// <param name="repository">The repository</param>
/// <param name="sha1">The SHA of the first commit.</param>
/// <param name="sha2">The SHA of the second commit.</param>
/// <param name="path">The relative path to the file.</param>
/// <param name="path">The relative path to the file (using '/' directory separator).</param>
/// <param name="contents">The contents to compare with the file.</param>
/// <returns>
/// A <see cref="Patch"/> object or null if the commit could not be found in the repository.
/// </returns>
/// <exception cref="ArgumentException">If <paramref name="path"/> contains a '\'.</exception>
Task<ContentChanges> CompareWith(IRepository repository, string sha1, string sha2, string path, byte[] contents);

/// <summary>
Expand Down
26 changes: 22 additions & 4 deletions test/GitHub.Exports.UnitTests/GitServiceIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public async Task Indent_Heuristic_Is_Enabled(string content1, string content2,
}

[TestCase("foo.txt", "a.b.", "bar.txt", "a.b.c.d.", 2)]
[TestCase(@"dir\foo.txt", "a.b.", @"dir\bar.txt", "a.b.c.d.", 2)]
[TestCase(@"dir\foo.txt", "a.b.", @"dir\foo.txt", "a.b.c.d.", 2)]
[TestCase(@"dir\unrelated.txt", "x.x.x.x.", @"dir\foo.txt", "a.b.c.d.", 4)]
public async Task Rename(string oldPath, string oldContent, string newPath, string newContent, int expectLinesAdded)
[TestCase(@"dir/foo.txt", "a.b.", @"dir/bar.txt", "a.b.c.d.", 2)]
[TestCase(@"dir/foo.txt", "a.b.", @"dir/foo.txt", "a.b.c.d.", 2)]
[TestCase(@"dir/unrelated.txt", "x.x.x.x.", @"dir/foo.txt", "a.b.c.d.", 4)]
public async Task Can_Handle_Renames(string oldPath, string oldContent, string newPath, string newContent, int expectLinesAdded)
{
using (var temp = new TempRepository())
{
Expand All @@ -114,6 +114,24 @@ public async Task Rename(string oldPath, string oldContent, string newPath, stri
Assert.That(changes?.LinesAdded, Is.EqualTo(expectLinesAdded));
}
}

[Test]
public void Path_Must_Not_Use_Windows_Directory_Separator()
{
using (var temp = new TempRepository())
{
var path = @"dir\foo.txt";
var oldContent = "oldContent";
var newContent = "newContent";
var commit1 = AddCommit(temp.Repository, path, oldContent);
var commit2 = AddCommit(temp.Repository, path, newContent);
var contentBytes = new UTF8Encoding(false).GetBytes(newContent);
var target = new GitService(new RepositoryFacade());

Assert.ThrowsAsync<ArgumentException>(() =>
target.CompareWith(temp.Repository, commit1.Sha, commit2.Sha, path, contentBytes));
}
}
}

public class TheCreateLocalRepositoryModelMethod
Expand Down
0