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

Commit b717470

Browse files
committed
Use Path.DirectorySeparatorChar
Use Path.DirectorySeparatorChar instead of hard coded backslashes for improved Unix and Linux support.
1 parent 5e73530 commit b717470

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/GitTools.Core.Tests/Git/GitRepositoryFactoryTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
3131
{
3232
using (var fixture = new EmptyRepositoryFixture())
3333
{
34-
var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split('\\').Last());
34+
var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last());
3535

3636
fixture.Repository.MakeCommits(5);
3737
fixture.Repository.CreateFileAndCommit("TestFile.txt");
@@ -52,7 +52,7 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
5252
dynamicRepositoryPath = gitRepository.DotGitDirectory;
5353

5454
gitRepository.IsDynamic.ShouldBe(true);
55-
gitRepository.DotGitDirectory.ShouldBe(expectedDynamicRepoLocation + "\\.git");
55+
gitRepository.DotGitDirectory.ShouldBe(expectedDynamicRepoLocation + Path.DirectorySeparatorChar + ".git");
5656

5757
var currentBranch = gitRepository.Repository.Head.CanonicalName;
5858

@@ -133,7 +133,7 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
133133
{
134134
fixture.Repository.CreateFileAndCommit("TestFile.txt");
135135
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));
136-
expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split('\\').Last());
136+
expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last());
137137
Directory.CreateDirectory(expectedDynamicRepoLocation);
138138

139139
var repositoryInfo = new RepositoryInfo
@@ -145,7 +145,7 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
145145
using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo))
146146
{
147147
gitRepository.IsDynamic.ShouldBe(true);
148-
gitRepository.DotGitDirectory.ShouldBe(expectedDynamicRepoLocation + "_1\\.git");
148+
gitRepository.DotGitDirectory.ShouldBe(expectedDynamicRepoLocation + "_1" + Path.DirectorySeparatorChar + ".git");
149149
}
150150
}
151151
}

src/GitTools.Core/GitTools.Core.Shared/Git/Extensions/LibGitExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ public static string GetRepositoryDirectory(this IRepository repository, bool om
9999
{
100100
var gitDirectory = repository.Info.Path;
101101

102-
gitDirectory = gitDirectory.TrimEnd('\\');
102+
gitDirectory = gitDirectory.TrimEnd(Path.DirectorySeparatorChar);
103103

104104
if (omitGitPostFix && gitDirectory.EndsWith(".git"))
105105
{
106106
gitDirectory = gitDirectory.Substring(0, gitDirectory.Length - ".git".Length);
107-
gitDirectory = gitDirectory.TrimEnd('\\');
107+
gitDirectory = gitDirectory.TrimEnd(Path.DirectorySeparatorChar);
108108
}
109109

110110
return gitDirectory;

0 commit comments

Comments
 (0)