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

Commit 586de7a

Browse files
Merge pull request #921 from github-for-unity/strange-file-names
Handling file names that look like they are a drive letter
2 parents d6fcd33 + 4b08403 commit 586de7a

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static bool HasNonDotDotLastElement(List<string> stack)
113113

114114
private static string ParseDriveLetter(string path, out string driveLetter)
115115
{
116-
if (path.Length >= 2 && path[1] == ':')
116+
if (path.Length >= 3 && path[1] == ':' && (path[2] == '/' || path[2] == '\\'))
117117
{
118118
driveLetter = path[0].ToString();
119119
return path.Substring(2);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using GitHub.Unity;
2+
using NCrunch.Framework;
3+
using NSubstitute;
4+
using NUnit.Framework;
5+
using TestUtils;
6+
7+
namespace UnitTests
8+
{
9+
[TestFixture, Isolated]
10+
class GitObjectFactoryTests
11+
{
12+
private static readonly SubstituteFactory SubstituteFactory = new SubstituteFactory();
13+
14+
[Test]
15+
public void ShouldParseNormalFile()
16+
{
17+
NPath.FileSystem = SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions() {
18+
CurrentDirectory = @"c:\Projects\UnityProject"
19+
});
20+
21+
var environment = Substitute.For<IEnvironment>();
22+
environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath());
23+
environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath());
24+
25+
var gitObjectFactory = new GitObjectFactory(environment);
26+
var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry("hello.txt", GitFileStatus.Deleted);
27+
28+
Assert.AreEqual(@"c:\Projects\UnityProject\hello.txt", gitStatusEntry.FullPath);
29+
}
30+
31+
32+
[Test]
33+
public void ShouldParseOddFile()
34+
{
35+
NPath.FileSystem = SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions()
36+
{
37+
CurrentDirectory = @"c:\Projects\UnityProject"
38+
});
39+
40+
var environment = Substitute.For<IEnvironment>();
41+
environment.RepositoryPath.Returns(@"c:\Projects\UnityProject".ToNPath());
42+
environment.UnityProjectPath.Returns(@"c:\Projects\UnityProject".ToNPath());
43+
44+
var gitObjectFactory = new GitObjectFactory(environment);
45+
var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry("c:UsersOculusGoVideo.mp4", GitFileStatus.Deleted);
46+
47+
Assert.AreEqual(@"c:\Projects\UnityProject\c:UsersOculusGoVideo.mp4", gitStatusEntry.FullPath);
48+
}
49+
}
50+
}

src/tests/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Compile Include="Git\GitConfigTests.cs" />
7777
<Compile Include="IO\BranchListOutputProcessorTests.cs" />
7878
<Compile Include="Extensions\EnvironmentExtensionTests.cs" />
79+
<Compile Include="IO\GitObjectFactoryTests.cs" />
7980
<Compile Include="IO\LfsVersionOutputProcessorTests.cs" />
8081
<Compile Include="IO\LinuxDiskUsageOutputProcessorTests.cs" />
8182
<Compile Include="IO\LockOutputProcessorTests.cs" />

0 commit comments

Comments
 (0)