Skip to content

Commit 9417555

Browse files
committed
Add .git file parsing, VS2019 - Switching solutions disables TGIT #59
1 parent 94a149a commit 9417555

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

TGit/Helpers/FileHelper.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.IO;
55
using System.Linq;
6+
using System.Text.RegularExpressions;
67
using System.Windows.Forms;
78

89
namespace SamirBoulema.TGit.Helpers
@@ -11,7 +12,7 @@ public static class FileHelper
1112
{
1213
public static string GetTortoiseGitProc()
1314
{
14-
return (string) Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");
15+
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");
1516
}
1617

1718
public static string GetTortoiseGitPlink()
@@ -30,17 +31,39 @@ public static void SaveAllFiles(DTE dte)
3031
dte.ExecuteCommand("File.SaveAll");
3132
}
3233

34+
/// <summary>
35+
/// Check if we have an open solution or a folder and try to find the base repository/solution dir
36+
/// </summary>
37+
/// <param name="dte"></param>
38+
/// <returns>Path to the base repository/solution dir</returns>
3339
public static string GetSolutionDir(DTE dte)
3440
{
35-
string fileName = dte.Solution.FullName;
36-
if (!string.IsNullOrEmpty(fileName))
41+
var fullName = dte.Solution.FullName;
42+
43+
if (string.IsNullOrEmpty(fullName))
44+
{
45+
return string.Empty;
46+
}
47+
48+
if (File.Exists(fullName))
3749
{
38-
var path = Path.GetDirectoryName(fileName);
50+
var path = Path.GetDirectoryName(fullName);
3951
return FindGitdir(path);
4052
}
53+
54+
if (Directory.Exists(fullName))
55+
{
56+
return FindGitdir(fullName);
57+
}
58+
4159
return string.Empty;
4260
}
4361

62+
/// <summary>
63+
/// Start at the solution dir and traverse up to find a .git folder or file
64+
/// </summary>
65+
/// <param name="path">Path to start traversing from.</param>
66+
/// <returns>Path to the .git folder or file.</returns>
4467
private static string FindGitdir(string path)
4568
{
4669
try
@@ -50,6 +73,18 @@ private static string FindGitdir(string path)
5073
{
5174
return di.FullName;
5275
}
76+
77+
var gitFilePath = Path.Combine(path, ".git");
78+
if (File.Exists(gitFilePath))
79+
{
80+
var text = File.ReadAllText(gitFilePath);
81+
var match = Regex.Match(text, "gitdir:(.*)");
82+
if (match.Success)
83+
{
84+
return match.Groups[1].Value.Trim();
85+
}
86+
}
87+
5388
if (di.Parent != null)
5489
{
5590
return FindGitdir(di.Parent.FullName);

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ variables:
1818
buildPlatform: 'Any CPU'
1919
buildConfiguration: 'Release'
2020

21-
name: 4.14.$(patch)
21+
name: 4.15.$(patch)
2222

2323
steps:
2424
- task: NuGetToolInstaller@0

0 commit comments

Comments
 (0)