Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion GVFS/GVFS.Common/FileSystem/HooksInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static HooksInstaller()
public static string MergeHooksData(string[] defaultHooksLines, string filename, string hookName)
{
IEnumerable<string> valuableHooksLines = defaultHooksLines.Where(line => !string.IsNullOrEmpty(line.Trim()));
string absolutePathToHooksExecutable = Path.Combine(ExecutingDirectory, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
/* Wrap in quotes to handle spaces in the path */
string absolutePathToHooksExecutable = $"\"{Path.Combine(ExecutingDirectory, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName)}\"";

if (valuableHooksLines.Contains(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName, GVFSPlatform.Instance.Constants.PathComparer))
{
Expand Down
1 change: 0 additions & 1 deletion GVFS/GVFS.Common/GVFSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public abstract class GVFSPlatformConstants

public abstract string GVFSExecutableName { get; }

public abstract string ProgramLocaterCommand { get; }

/// <summary>
/// Different platforms can have different requirements
Expand Down
24 changes: 17 additions & 7 deletions GVFS/GVFS.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ public bool TryGetFromConfig(string settingName, bool forceOutsideEnlistment, ou

public ConfigResult GetOriginUrl()
{
return new ConfigResult(this.InvokeGitAgainstDotGitFolder("config --local remote.origin.url"), "remote.origin.url");
/* Disable precommand hook because this config call is used during mounting process
* which needs to be able to fix a bad precommand hook configuration. */
return new ConfigResult(this.InvokeGitAgainstDotGitFolder("config --local remote.origin.url", usePreCommandHook: false), "remote.origin.url");
}

public Result DiffTree(string sourceTreeish, string targetTreeish, Action<string> onResult)
Expand Down Expand Up @@ -670,7 +672,7 @@ public Result MultiPackIndexRepack(string gitObjectDirectory, string batchSize)
return this.InvokeGitAgainstDotGitFolder($"-c pack.threads=1 -c repack.packKeptObjects=true multi-pack-index repack --object-dir=\"{gitObjectDirectory}\" --batch-size={batchSize} --no-progress");
}

public Process GetGitProcess(string command, string workingDirectory, string dotGitDirectory, bool useReadObjectHook, bool redirectStandardError, string gitObjectsDirectory)
public Process GetGitProcess(string command, string workingDirectory, string dotGitDirectory, bool useReadObjectHook, bool redirectStandardError, string gitObjectsDirectory, bool usePreCommandHook)
{
ProcessStartInfo processInfo = new ProcessStartInfo(this.gitBinPath);
processInfo.WorkingDirectory = workingDirectory;
Expand Down Expand Up @@ -719,6 +721,11 @@ public Process GetGitProcess(string command, string workingDirectory, string dot
command = "-c " + GitConfigSetting.CoreVirtualizeObjectsName + "=false " + command;
}

if (!usePreCommandHook)
{
processInfo.EnvironmentVariables["COMMAND_HOOK_LOCK"] = "true";
}

if (!string.IsNullOrEmpty(dotGitDirectory))
{
command = "--git-dir=\"" + dotGitDirectory + "\" " + command;
Expand All @@ -740,7 +747,8 @@ protected virtual Result InvokeGitImpl(
Action<StreamWriter> writeStdIn,
Action<string> parseStdOutLine,
int timeoutMs,
string gitObjectsDirectory = null)
string gitObjectsDirectory = null,
bool usePreCommandHook = true)
{
if (failedToSetEncoding && writeStdIn != null)
{
Expand All @@ -752,7 +760,7 @@ protected virtual Result InvokeGitImpl(
// From https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
// To avoid deadlocks, use asynchronous read operations on at least one of the streams.
// Do not perform a synchronous read to the end of both redirected streams.
using (this.executingProcess = this.GetGitProcess(command, workingDirectory, dotGitDirectory, useReadObjectHook, redirectStandardError: true, gitObjectsDirectory: gitObjectsDirectory))
using (this.executingProcess = this.GetGitProcess(command, workingDirectory, dotGitDirectory, useReadObjectHook, redirectStandardError: true, gitObjectsDirectory: gitObjectsDirectory, usePreCommandHook: usePreCommandHook))
{
StringBuilder output = new StringBuilder();
StringBuilder errors = new StringBuilder();
Expand Down Expand Up @@ -904,15 +912,16 @@ private Result InvokeGitInWorkingDirectoryRoot(
/// Invokes git.exe against an enlistment's .git folder.
/// This method should be used only with git-commands that ignore the working directory
/// </summary>
private Result InvokeGitAgainstDotGitFolder(string command)
private Result InvokeGitAgainstDotGitFolder(string command, bool usePreCommandHook = true)
{
return this.InvokeGitAgainstDotGitFolder(command, null, null);
return this.InvokeGitAgainstDotGitFolder(command, null, null, usePreCommandHook: usePreCommandHook);
}

private Result InvokeGitAgainstDotGitFolder(
string command,
Action<StreamWriter> writeStdIn,
Action<string> parseStdOutLine,
bool usePreCommandHook = true,
string gitObjectsDirectory = null)
{
// This git command should not need/use the working directory of the repo.
Expand All @@ -926,7 +935,8 @@ private Result InvokeGitAgainstDotGitFolder(
writeStdIn: writeStdIn,
parseStdOutLine: parseStdOutLine,
timeoutMs: -1,
gitObjectsDirectory: gitObjectsDirectory);
gitObjectsDirectory: gitObjectsDirectory,
usePreCommandHook: usePreCommandHook);
}

public class Result
Expand Down
11 changes: 10 additions & 1 deletion GVFS/GVFS.Common/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ public static string GetCurrentProcessVersion()

public static bool IsDevelopmentVersion()
{
Version currentVersion = new Version(ProcessHelper.GetCurrentProcessVersion());
string version = ProcessHelper.GetCurrentProcessVersion();
/* When debugging local version with VS, the version will include +{commitId} suffix,
* which is not valid for Version class. */
var plusIndex = version.IndexOf('+');
if (plusIndex >= 0)
{
version = version.Substring(0, plusIndex);
}

Version currentVersion = new Version(version);

return currentVersion.Major == 0;
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Platform.Windows/WindowsGitInstallation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public bool GitExists(string gitBinPath)
return File.Exists(gitBinPath);
}

return ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GitProcessName) != null;
return !string.IsNullOrEmpty(GetInstalledGitBinPath());
}

public string GetInstalledGitBinPath()
Expand Down
34 changes: 16 additions & 18 deletions GVFS/GVFS.Platform.Windows/WindowsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,28 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
try
{
const string GitBinPathEnd = "\\cmd\\git.exe";
string[] gitVSRegistryKeyNames =
{
"HKEY_CURRENT_USER\\Software\\Microsoft\\VSCommon\\15.0\\TeamFoundation\\GitSourceControl",
"HKEY_CURRENT_USER\\Software\\Microsoft\\VSCommon\\16.0\\TeamFoundation\\GitSourceControl"
};
const string VSRegistryKeyRoot = @"Software\Microsoft\VSCommon";
const string GitVSRegistrySubKey = @"TeamFoundation\GitSourceControl";
const string GitVSRegistryValueName = "GitPath";

if (!gitBinPath.EndsWith(GitBinPathEnd))
{
tracer.RelatedWarning(
"Unable to configure Visual Studio’s GitSourceControl regkey because invalid git.exe path found: " + gitBinPath,
Keywords.Telemetry);

return;
}

string regKeyValue = gitBinPath.Substring(0, gitBinPath.Length - GitBinPathEnd.Length);
foreach (string registryKeyName in gitVSRegistryKeyNames)

/* Get all versions of Visual Studio that exist in the registry at least 15.0.
* This attempts to future proof (current version is 17.0), but may need to be
* revisited in the future if VS changes how it stores this. */
var vsVersions = Registry.CurrentUser.OpenSubKey(VSRegistryKeyRoot)
?.GetSubKeyNames()
.Where(name => Version.TryParse(name, out var version) && version.Major >= 15)
.ToArray() ?? Array.Empty<string>();

foreach (string version in vsVersions)
{
var registryKeyName = $@"{Registry.CurrentUser.Name}\{VSRegistryKeyRoot}\{version}\{GitVSRegistrySubKey}";
Registry.SetValue(registryKeyName, GitVSRegistryValueName, regKeyValue);
}
}
Expand All @@ -255,14 +258,14 @@ public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string
{
error = null;
hooksVersion = null;
string hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
if (hooksPath == null)
string hooksPath = Path.Combine(ProcessHelper.GetCurrentProcessLocation(), GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
if (hooksPath == null || !File.Exists(hooksPath))
{
error = "Could not find " + GVFSPlatform.Instance.Constants.GVFSHooksExecutableName;
return false;
}

FileVersionInfo hooksFileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(hooksPath, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName));
FileVersionInfo hooksFileVersionInfo = FileVersionInfo.GetVersionInfo(hooksPath);
hooksVersion = hooksFileVersionInfo.ProductVersion;
return true;
}
Expand Down Expand Up @@ -441,11 +444,6 @@ public override string GVFSExecutableName
get { return "GVFS" + this.ExecutableExtension; }
}

public override string ProgramLocaterCommand
{
get { return "where"; }
}

public override HashSet<string> UpgradeBlockingProcesses
{
get { return new HashSet<string>(GVFSPlatform.Instance.Constants.PathComparer) { "GVFS", "GVFS.Mount", "git", "ssh-agent", "wish", "bash" }; }
Expand Down
4 changes: 1 addition & 3 deletions GVFS/GVFS.UnitTests/CommandLine/HooksInstallerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public class HooksInstallerTests
{
private const string Filename = "hooksfile";
private readonly string expectedAbsoluteGvfsHookPath =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
$"\"{Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), GVFSPlatform.Instance.Constants.GVFSHooksExecutableName)}\"";

[TestCase]
[Category(CategoryConstants.ExceptionExpected)]
Expand Down
5 changes: 0 additions & 5 deletions GVFS/GVFS.UnitTests/Mock/Common/MockPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ public override string GVFSExecutableName
{
get { return "MockGVFS" + this.ExecutableExtension; }
}

public override string ProgramLocaterCommand
{
get { return "MockWhere"; }
}

public override HashSet<string> UpgradeBlockingProcesses
{
Expand Down
3 changes: 2 additions & 1 deletion GVFS/GVFS.UnitTests/Mock/Git/MockGitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ protected override Result InvokeGitImpl(
Action<StreamWriter> writeStdIn,
Action<string> parseStdOutLine,
int timeoutMs,
string gitObjectsDirectory = null)
string gitObjectsDirectory = null,
bool usePrecommandHook = true)
{
this.CommandsRun.Add(command);

Expand Down
8 changes: 7 additions & 1 deletion GVFS/GVFS/CommandLine/GVFSVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,14 @@ private bool TryValidateGVFSVersion(GVFSEnlistment enlistment, ITracer tracer, S

using (ITracer activity = tracer.StartActivity("ValidateGVFSVersion", EventLevel.Informational))
{
Version currentVersion = new Version(ProcessHelper.GetCurrentProcessVersion());
if (ProcessHelper.IsDevelopmentVersion())
{
/* Development Version will start with 0 and include a "+{commitID}" suffix
* so it won't ever be valid, but it needs to be able to run so we can test it. */
return true;
}

Version currentVersion = new Version(ProcessHelper.GetCurrentProcessVersion());
IEnumerable<ServerGVFSConfig.VersionRange> allowedGvfsClientVersions =
config != null
? config.AllowedGVFSClientVersions
Expand Down