Skip to content

Commit

Permalink
PathUtil.GetDirectoryName did not accept root dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardol committed Sep 16, 2019
1 parent f944048 commit 22dafca
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 53 deletions.
6 changes: 3 additions & 3 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public static string TryFindGitWorkingDir([CanBeNull] string startDir)
return dir.EnsureTrailingPathSeparator();
}

dir = PathUtil.GetDirectoryName(dir);
dir = Path.GetDirectoryName(dir);
}

return null;
Expand Down Expand Up @@ -1222,8 +1222,8 @@ public string GetCurrentSubmoduleLocalPath()

Debug.Assert(WorkingDir.StartsWith(SuperprojectModule.WorkingDir), "Submodule working dir should start with super-project's working dir");

return PathUtil.GetDirectoryName(
WorkingDir.Substring(SuperprojectModule.WorkingDir.Length).ToPosixPath());
return Path.GetDirectoryName(
WorkingDir.Substring(SuperprojectModule.WorkingDir.Length)).ToPosixPath();
}

public string GetSubmoduleFullPath(string localPath)
Expand Down
23 changes: 0 additions & 23 deletions GitCommands/PathUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,6 @@ public static string GetFileName([NotNull] string fileName)
return fileName;
}

[NotNull]
public static string GetDirectoryName([NotNull] string fileName)
{
var pathSeparators = new[] { NativeDirectorySeparatorChar, PosixDirectorySeparatorChar };
var pos = fileName.LastIndexOfAny(pathSeparators);
if (pos != -1)
{
if (pos == 0 && fileName[0] == PosixDirectorySeparatorChar)
{
return fileName.Length == 1 ? "" : PosixDirectorySeparatorChar.ToString();
}

fileName = fileName.Substring(0, pos);
}

if (fileName.Length == 2 && char.IsLetter(fileName[0]) && fileName[1] == Path.VolumeSeparatorChar)
{
return "";
}

return fileName;
}

[NotNull]
public static string NormalizePath([NotNull] this string path)
{
Expand Down
4 changes: 2 additions & 2 deletions GitCommands/Submodules/SubmoduleStatusProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void SetSuperProjectSubmoduleInfo(GitModule superprojectModule, Submodul
else
{
var localPath = superprojectModule.WorkingDir.Substring(topProject.WorkingDir.Length);
name = PathUtil.GetDirectoryName(localPath.ToPosixPath());
name = Path.GetDirectoryName(localPath).ToPosixPath();
}

string path = superprojectModule.WorkingDir;
Expand Down Expand Up @@ -260,7 +260,7 @@ private void SetSubmoduleData(GitModule currentModule, SubmoduleInfoResult resul
if (submodules.Any())
{
string localPath = result.Module.WorkingDir.Substring(topProject.WorkingDir.Length);
localPath = PathUtil.GetDirectoryName(localPath.ToPosixPath());
localPath = Path.GetDirectoryName(localPath).ToPosixPath();

foreach (var submodule in submodules)
{
Expand Down
3 changes: 2 additions & 1 deletion GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -317,7 +318,7 @@ private void CreateSubmoduleNodes(IEnumerable<SubmoduleInfo> submodules, GitModu
foreach (var submoduleInfo in submodules)
{
string superPath = GetSubmoduleSuperPath(submoduleInfo.Path);
string localPath = PathUtil.GetDirectoryName(submoduleInfo.Path.Substring(superPath.Length).ToPosixPath());
string localPath = Path.GetDirectoryName(submoduleInfo.Path.Substring(superPath.Length)).ToPosixPath();

var isCurrent = submoduleInfo.Bold;
nodes.Add(new SubmoduleNode(this, submoduleInfo, isCurrent, localPath, superPath));
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormResolveConflicts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ private void SaveAs(string side)
using (var fileDialog = new SaveFileDialog
{
FileName = fileName,
InitialDirectory = _fullPathResolver.Resolve(PathUtil.GetDirectoryName(conflictData.Filename)),
InitialDirectory = _fullPathResolver.Resolve(Path.GetDirectoryName(conflictData.Filename)),
AddExtension = true
})
{
Expand Down
23 changes: 0 additions & 23 deletions UnitTests/GitCommandsTests/Helpers/PathUtilTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,6 @@ public void GetFileNameTest()
}
}

[Test]
public void GetDirectoryNameTest()
{
if (Path.DirectorySeparatorChar == '\\')
{
Assert.AreEqual(PathUtil.GetDirectoryName("\\\\my-pc\\Work\\GitExtensions\\"), "\\\\my-pc\\Work\\GitExtensions");
Assert.AreEqual(PathUtil.GetDirectoryName("C:\\Work\\GitExtensions\\"), "C:\\Work\\GitExtensions");
Assert.AreEqual(PathUtil.GetDirectoryName("C:\\Work\\GitExtensions"), "C:\\Work");
Assert.AreEqual(PathUtil.GetDirectoryName("C:\\Work\\"), "C:\\Work");
Assert.AreEqual(PathUtil.GetDirectoryName("C:\\Work"), "");
Assert.AreEqual(PathUtil.GetDirectoryName("C:\\"), "");
Assert.AreEqual(PathUtil.GetDirectoryName("C:"), "");
Assert.AreEqual(PathUtil.GetDirectoryName(""), "");
}

Assert.AreEqual(PathUtil.GetDirectoryName("//my-pc/Work/GitExtensions/"), "//my-pc/Work/GitExtensions");
Assert.AreEqual(PathUtil.GetDirectoryName("/Work/GitExtensions/"), "/Work/GitExtensions");
Assert.AreEqual(PathUtil.GetDirectoryName("/Work/GitExtensions"), "/Work");
Assert.AreEqual(PathUtil.GetDirectoryName("/Work/"), "/Work");
Assert.AreEqual(PathUtil.GetDirectoryName("/"), "");
Assert.AreEqual("/", PathUtil.GetDirectoryName("/Work"), "/Work");
}

[Test]
public void GetRepositoryNameTest()
{
Expand Down

0 comments on commit 22dafca

Please sign in to comment.