Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Handling file names that look like they are a drive letter #921

Merged
merged 3 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/GitHub.Api/IO/NiceIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static bool HasNonDotDotLastElement(List<string> 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);
Expand Down
50 changes: 50 additions & 0 deletions src/tests/UnitTests/IO/GitObjectFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -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 = Substitute.For<IEnvironment>();
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 = Substitute.For<IEnvironment>();
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHO NAMES THEIR FILES THIS? 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

}
}
}
1 change: 1 addition & 0 deletions src/tests/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="Git\GitConfigTests.cs" />
<Compile Include="IO\BranchListOutputProcessorTests.cs" />
<Compile Include="Extensions\EnvironmentExtensionTests.cs" />
<Compile Include="IO\GitObjectFactoryTests.cs" />
<Compile Include="IO\LfsVersionOutputProcessorTests.cs" />
<Compile Include="IO\LinuxDiskUsageOutputProcessorTests.cs" />
<Compile Include="IO\LockOutputProcessorTests.cs" />
Expand Down