From 4b0769c5400009b78a9d85fd15b247d3c5c219f2 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 3 Oct 2018 11:23:12 -0400 Subject: [PATCH 1/3] Adding a test that proves the error --- .../UnitTests/IO/GitObjectFactoryTests.cs | 50 +++++++++++++++++++ src/tests/UnitTests/UnitTests.csproj | 1 + 2 files changed, 51 insertions(+) create mode 100644 src/tests/UnitTests/IO/GitObjectFactoryTests.cs diff --git a/src/tests/UnitTests/IO/GitObjectFactoryTests.cs b/src/tests/UnitTests/IO/GitObjectFactoryTests.cs new file mode 100644 index 000000000..d306a0111 --- /dev/null +++ b/src/tests/UnitTests/IO/GitObjectFactoryTests.cs @@ -0,0 +1,50 @@ +using GitHub.Unity; +using NCrunch.Framework; +using NSubstitute; +using NUnit.Framework; +using TestUtils; + +namespace UnitTests +{ + [TestFixture, Isolated] + class GitObjectFactoryTests + { + private static readonly SubstituteFactory SubstituteFactory = new SubstituteFactory(); + + [Test] + public void ShouldParseNormalFile() + { + NPath.FileSystem = SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions() { + CurrentDirectory = @"c:\Projects\UnityProject" + }); + + var environment = NSubstitute.Substitute.For(); + environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath()); + environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath()); + + var gitObjectFactory = new GitObjectFactory(environment); + var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry("hello.txt", GitFileStatus.Deleted); + + Assert.AreEqual(@"c:\Projects\UnityProject\hello.txt", gitStatusEntry.FullPath); + } + + + [Test] + public void ShouldParseOddFile() + { + NPath.FileSystem = SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions() + { + CurrentDirectory = @"c:\Projects\UnityProject" + }); + + var environment = NSubstitute.Substitute.For(); + environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath()); + environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath()); + + var gitObjectFactory = new GitObjectFactory(environment); + var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry("c:UsersOculusGoVideo.mp4", GitFileStatus.Deleted); + + Assert.AreEqual(@"c:\Projects\UnityProject\c:UsersOculusGoVideo.mp4", gitStatusEntry.FullPath); + } + } +} \ No newline at end of file diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index bff3c8d57..e172e1b74 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -76,6 +76,7 @@ + From 3a9593c3766e76dd3d6d7ec6d3b4aceac8441202 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 3 Oct 2018 11:24:41 -0400 Subject: [PATCH 2/3] Fixing the issue --- src/GitHub.Api/IO/NiceIO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub.Api/IO/NiceIO.cs b/src/GitHub.Api/IO/NiceIO.cs index bf008660c..c8605de6a 100644 --- a/src/GitHub.Api/IO/NiceIO.cs +++ b/src/GitHub.Api/IO/NiceIO.cs @@ -113,7 +113,7 @@ private static bool HasNonDotDotLastElement(List stack) private static string ParseDriveLetter(string path, out string driveLetter) { - if (path.Length >= 2 && path[1] == ':') + if (path.Length >= 3 && path[1] == ':' && (path[2] == '/' || path[2] == '\\')) { driveLetter = path[0].ToString(); return path.Substring(2); From 4b08403bf9eb37978036ffa190eb476aabe83f8e Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 3 Oct 2018 11:28:57 -0400 Subject: [PATCH 3/3] Cleanup --- src/tests/UnitTests/IO/GitObjectFactoryTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/UnitTests/IO/GitObjectFactoryTests.cs b/src/tests/UnitTests/IO/GitObjectFactoryTests.cs index d306a0111..35c98d5cd 100644 --- a/src/tests/UnitTests/IO/GitObjectFactoryTests.cs +++ b/src/tests/UnitTests/IO/GitObjectFactoryTests.cs @@ -18,7 +18,7 @@ public void ShouldParseNormalFile() CurrentDirectory = @"c:\Projects\UnityProject" }); - var environment = NSubstitute.Substitute.For(); + var environment = Substitute.For(); environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath()); environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath()); @@ -37,7 +37,7 @@ public void ShouldParseOddFile() CurrentDirectory = @"c:\Projects\UnityProject" }); - var environment = NSubstitute.Substitute.For(); + var environment = Substitute.For(); environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath()); environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath()); @@ -47,4 +47,4 @@ public void ShouldParseOddFile() Assert.AreEqual(@"c:\Projects\UnityProject\c:UsersOculusGoVideo.mp4", gitStatusEntry.FullPath); } } -} \ No newline at end of file +}