Skip to content

Commit

Permalink
Add .git file parsing, VS2019 - Switching solutions disables TGIT #59
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Dec 12, 2019
1 parent 94a149a commit 9417555
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
43 changes: 39 additions & 4 deletions TGit/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace SamirBoulema.TGit.Helpers
Expand All @@ -11,7 +12,7 @@ public static class FileHelper
{
public static string GetTortoiseGitProc()
{
return (string) Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");
}

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

/// <summary>
/// Check if we have an open solution or a folder and try to find the base repository/solution dir
/// </summary>
/// <param name="dte"></param>
/// <returns>Path to the base repository/solution dir</returns>
public static string GetSolutionDir(DTE dte)
{
string fileName = dte.Solution.FullName;
if (!string.IsNullOrEmpty(fileName))
var fullName = dte.Solution.FullName;

if (string.IsNullOrEmpty(fullName))
{
return string.Empty;
}

if (File.Exists(fullName))
{
var path = Path.GetDirectoryName(fileName);
var path = Path.GetDirectoryName(fullName);
return FindGitdir(path);
}

if (Directory.Exists(fullName))
{
return FindGitdir(fullName);
}

return string.Empty;
}

/// <summary>
/// Start at the solution dir and traverse up to find a .git folder or file
/// </summary>
/// <param name="path">Path to start traversing from.</param>
/// <returns>Path to the .git folder or file.</returns>
private static string FindGitdir(string path)
{
try
Expand All @@ -50,6 +73,18 @@ private static string FindGitdir(string path)
{
return di.FullName;
}

var gitFilePath = Path.Combine(path, ".git");
if (File.Exists(gitFilePath))
{
var text = File.ReadAllText(gitFilePath);
var match = Regex.Match(text, "gitdir:(.*)");
if (match.Success)
{
return match.Groups[1].Value.Trim();
}
}

if (di.Parent != null)
{
return FindGitdir(di.Parent.FullName);
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'

name: 4.14.$(patch)
name: 4.15.$(patch)

steps:
- task: NuGetToolInstaller@0
Expand Down

0 comments on commit 9417555

Please sign in to comment.