Skip to content

Commit

Permalink
Merge pull request #25 Remove more dead hooks code
Browse files Browse the repository at this point in the history
Remove more dead hooks code
  • Loading branch information
wilbaker authored Aug 8, 2019
2 parents 6660a70 + a67ca85 commit 5b6a1cf
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 226 deletions.
28 changes: 0 additions & 28 deletions GVFS/GVFS.Common/FileSystem/HooksInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ static HooksInstaller()
ExecutingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

public static string MergeHooksData(string[] defaultHooksLines, string filename, string hookName)
{
IEnumerable<string> valuableHooksLines = defaultHooksLines.Where(line => !string.IsNullOrEmpty(line.Trim()));

if (valuableHooksLines.Contains(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName, StringComparer.OrdinalIgnoreCase))
{
throw new HooksConfigurationException(
$"{GVFSPlatform.Instance.Constants.GVFSHooksExecutableName} should not be specified in the configuration for "
+ GVFSConstants.DotGit.Hooks.ReadObjectName + " hooks (" + filename + ").");
}
else if (!valuableHooksLines.Any())
{
return GVFSPlatform.Instance.Constants.GVFSHooksExecutableName;
}
else
{
return string.Join("\n", valuableHooksLines.Concat(new string[] { GVFSPlatform.Instance.Constants.GVFSHooksExecutableName }));
}
}

public static bool InstallHooks(GVFSContext context, out string error)
{
error = string.Empty;
Expand Down Expand Up @@ -202,14 +182,6 @@ private static bool TryUpdateHook(
return true;
}

public class HooksConfigurationException : Exception
{
public HooksConfigurationException(string message)
: base(message)
{
}
}

private class HookData
{
public HookData(string name, string path, string executableName)
Expand Down
2 changes: 0 additions & 2 deletions GVFS/GVFS.Common/GVFSConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public static class GitConfig
public const string EnlistmentId = GVFSPrefix + "enlistment-id";
public const string CacheServer = GVFSPrefix + "cache-server";
public const string DeprecatedCacheEndpointSuffix = ".cache-server-url";
public const string HooksPrefix = GitConfig.GVFSPrefix + "clone.default-";
public const string GVFSTelemetryId = GitConfig.GVFSPrefix + "telemetry-id";
public const string GVFSTelemetryPipe = GitConfig.GVFSPrefix + "telemetry-pipe";
public const string IKey = GitConfig.GVFSPrefix + "ikey";
Expand Down Expand Up @@ -153,7 +152,6 @@ public static class Logs

public static class Hooks
{
public const string LoaderExecutable = "GitHooksLoader.exe";
public const string ReadObjectName = "read-object";
public static readonly string Root = Path.Combine(DotGit.Root, "hooks");
public static readonly string ReadObjectPath = Path.Combine(Hooks.Root, ReadObjectName);
Expand Down
11 changes: 0 additions & 11 deletions GVFS/GVFS.Common/GVFSEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public partial class GVFSEnlistment : Enlistment

private string gitVersion;
private string gvfsVersion;
private string gvfsHooksVersion;

// New enlistment
public GVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, GitAuthentication authentication)
Expand Down Expand Up @@ -75,11 +74,6 @@ public string GVFSVersion
get { return this.gvfsVersion; }
}

public string GVFSHooksVersion
{
get { return this.gvfsHooksVersion; }
}

public static GVFSEnlistment CreateFromDirectory(
string directory,
string gitBinRoot,
Expand Down Expand Up @@ -191,11 +185,6 @@ public void SetGVFSVersion(string gvfsVersion)
this.SetOnce(gvfsVersion, ref this.gvfsVersion);
}

public void SetGVFSHooksVersion(string gvfsHooksVersion)
{
this.SetOnce(gvfsHooksVersion, ref this.gvfsHooksVersion);
}

public void InitializeCachePathsFromKey(string localCacheRoot, string localCacheKey)
{
this.InitializeCachePaths(
Expand Down
8 changes: 0 additions & 8 deletions GVFS/GVFS.Common/GVFSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ public static void Register(GVFSPlatform platform)

public abstract void ConfigureVisualStudio(string gitBinPath, ITracer tracer);

public abstract bool TryGetGVFSHooksVersion(out string hooksVersion, out string error);
public abstract bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage);

public abstract bool TryVerifyAuthenticodeSignature(string path, out string subject, out string issuer, out string error);

public abstract Dictionary<string, string> GetPhysicalDiskInfo(string path, bool sizeStatsOnly);
Expand Down Expand Up @@ -169,11 +166,6 @@ public abstract class GVFSPlatformConstants
/// </summary>
public abstract HashSet<string> UpgradeBlockingProcesses { get; }

public string GVFSHooksExecutableName
{
get { return "GVFS.Hooks" + this.ExecutableExtension; }
}

public string GVFSReadObjectHookExecutableName
{
get { return "GVFS.ReadObjectHook" + this.ExecutableExtension; }
Expand Down
2 changes: 0 additions & 2 deletions GVFS/GVFS.Installer.Windows/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#define VCRuntimeDir PackagesDir + "\GVFS.VCRuntime.0.2.0-build\lib\x64"
#define GVFSDir BuildOutputDir + "\GVFS.Windows\bin\" + PlatformAndConfiguration
#define GVFSCommonDir BuildOutputDir + "\GVFS.Common\bin\" + PlatformAndConfiguration + "\netstandard2.0"
#define HooksDir BuildOutputDir + "\GVFS.Hooks.Windows\bin\" + PlatformAndConfiguration
#define HooksLoaderDir BuildOutputDir + "\GitHooksLoader\bin\" + PlatformAndConfiguration
#define ServiceDir BuildOutputDir + "\GVFS.Service.Windows\bin\" + PlatformAndConfiguration
#define ServiceUIDir BuildOutputDir + "\GVFS.Service.UI\bin\" + PlatformAndConfiguration
#define GVFSMountDir BuildOutputDir + "\GVFS.Mount.Windows\bin\" + PlatformAndConfiguration
Expand Down
22 changes: 0 additions & 22 deletions GVFS/GVFS.Platform.POSIX/POSIXPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,6 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
{
}

public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string error)
{
// TODO(#1044): Get the hooks version rather than the GVFS version (and share that code with the Windows platform)
hooksVersion = ProcessHelper.GetCurrentProcessVersion();
error = null;
return true;
}

public override bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage)
{
errorMessage = null;

string gvfsHooksPath = Path.Combine(executingDirectory, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);

File.WriteAllText(
commandHookPath,
$"#!/bin/sh\n{gvfsHooksPath} {hookName} \"$@\"");
GVFSPlatform.Instance.FileSystem.ChangeMode(commandHookPath, Convert.ToUInt16("755", 8));

return true;
}

public override bool TryVerifyAuthenticodeSignature(string path, out string subject, out string issuer, out string error)
{
throw new NotImplementedException();
Expand Down
1 change: 0 additions & 1 deletion GVFS/GVFS.Platform.Windows/GVFS.Platform.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindowsFileBasedLock.cs" />
<Compile Include="WindowsFileSystem.Shared.cs" />
<Compile Include="WindowsGitHooksInstaller.cs" />
<Compile Include="WindowsGitInstallation.cs" />
<Compile Include="WindowsPhysicalDiskInfo.cs" />
<Compile Include="WindowsPlatform.cs" />
Expand Down
55 changes: 0 additions & 55 deletions GVFS/GVFS.Platform.Windows/WindowsGitHooksInstaller.cs

This file was deleted.

42 changes: 0 additions & 42 deletions GVFS/GVFS.Platform.Windows/WindowsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,48 +255,6 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
}
}

public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string error)
{
error = null;
hooksVersion = null;
string hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
if (hooksPath == null)
{
error = "Could not find " + GVFSPlatform.Instance.Constants.GVFSHooksExecutableName;
return false;
}

FileVersionInfo hooksFileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(hooksPath, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName));
hooksVersion = hooksFileVersionInfo.ProductVersion;
return true;
}

public override bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage)
{
// The GitHooksLoader requires the following setup to invoke a hook:
// Copy GithooksLoader.exe to hook-name.exe
// Create a text file named hook-name.hooks that lists the applications to execute for the hook, one application per line

string gitHooksloaderPath = Path.Combine(executingDirectory, GVFSConstants.DotGit.Hooks.LoaderExecutable);
if (!HooksInstaller.TryHooksInstallationAction(
() => HooksInstaller.CopyHook(context, gitHooksloaderPath, commandHookPath + GVFSPlatform.Instance.Constants.ExecutableExtension),
out errorMessage))
{
errorMessage = "Failed to copy " + GVFSConstants.DotGit.Hooks.LoaderExecutable + " to " + commandHookPath + GVFSPlatform.Instance.Constants.ExecutableExtension + "\n" + errorMessage;
return false;
}

if (!HooksInstaller.TryHooksInstallationAction(
() => WindowsGitHooksInstaller.CreateHookCommandConfig(context, hookName, commandHookPath),
out errorMessage))
{
errorMessage = "Failed to create " + commandHookPath + GVFSConstants.GitConfig.HooksExtension + "\n" + errorMessage;
return false;
}

return true;
}

public override bool TryVerifyAuthenticodeSignature(string path, out string subject, out string issuer, out string error)
{
using (PowerShell powershell = PowerShell.Create())
Expand Down
35 changes: 12 additions & 23 deletions GVFS/GVFS.Service/Handlers/GetActiveRepoListHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,21 @@ public void Run()
private bool IsValidRepo(string repoRoot)
{
string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();

string hooksVersion = null;
string error = null;
if (GVFSPlatform.Instance.TryGetGVFSHooksVersion(out hooksVersion, out error))
try
{
try
{
GVFSEnlistment enlistment = GVFSEnlistment.CreateFromDirectory(
repoRoot,
gitBinPath,
authentication: null);
}
catch (InvalidRepoException e)
{
EventMetadata metadata = new EventMetadata();
metadata.Add(nameof(repoRoot), repoRoot);
metadata.Add(nameof(gitBinPath), gitBinPath);
metadata.Add("Exception", e.ToString());
this.tracer.RelatedInfo(metadata, $"{nameof(this.IsValidRepo)}: Found invalid repo");

return false;
}
GVFSEnlistment enlistment = GVFSEnlistment.CreateFromDirectory(
repoRoot,
gitBinPath,
authentication: null);
}
else
catch (InvalidRepoException e)
{
this.tracer.RelatedError($"{nameof(this.IsValidRepo)}: {nameof(GVFSPlatform.Instance.TryGetGVFSHooksVersion)} failed. {error}");
EventMetadata metadata = new EventMetadata();
metadata.Add(nameof(repoRoot), repoRoot);
metadata.Add(nameof(gitBinPath), gitBinPath);
metadata.Add("Exception", e.ToString());
this.tracer.RelatedInfo(metadata, $"{nameof(this.IsValidRepo)}: Found invalid repo");

return false;
}

Expand Down
10 changes: 0 additions & 10 deletions GVFS/GVFS.UnitTests/Mock/Common/MockPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
throw new NotSupportedException();
}

public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string error)
{
throw new NotSupportedException();
}

public override bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage)
{
throw new NotSupportedException();
}

public override bool TryVerifyAuthenticodeSignature(string path, out string subject, out string issuer, out string error)
{
throw new NotImplementedException();
Expand Down
2 changes: 0 additions & 2 deletions GVFS/GVFS/CommandLine/CloneVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ private Result TryCreateEnlistment(
return new Result(GVFSConstants.GitIsNotInstalledError);
}

this.CheckGVFSHooksVersion(tracer: null, hooksVersion: out _);

try
{
enlistment = new GVFSEnlistment(
Expand Down
18 changes: 0 additions & 18 deletions GVFS/GVFS/CommandLine/GVFSVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,6 @@ protected void ValidateClientVersions(ITracer tracer, GVFSEnlistment enlistment,
this.CheckGitVersion(tracer, enlistment, out string gitVersion);
enlistment.SetGitVersion(gitVersion);

this.CheckGVFSHooksVersion(tracer, out string hooksVersion);
enlistment.SetGVFSHooksVersion(hooksVersion);

string errorMessage = null;
bool errorIsFatal = false;
if (!this.TryValidateGVFSVersion(enlistment, tracer, gvfsConfig, out errorMessage, out errorIsFatal))
Expand Down Expand Up @@ -413,21 +410,6 @@ protected bool TryCreateAlternatesFile(PhysicalFileSystem fileSystem, GVFSEnlist
return true;
}

protected void CheckGVFSHooksVersion(ITracer tracer, out string hooksVersion)
{
string error;
if (!GVFSPlatform.Instance.TryGetGVFSHooksVersion(out hooksVersion, out error))
{
this.ReportErrorAndExit(tracer, error);
}

string gvfsVersion = ProcessHelper.GetCurrentProcessVersion();
if (hooksVersion != gvfsVersion)
{
this.ReportErrorAndExit(tracer, "GVFS.Hooks version ({0}) does not match GVFS version ({1}).", hooksVersion, gvfsVersion);
}
}

protected void BlockEmptyCacheServerUrl(string userInput)
{
if (userInput == null)
Expand Down
2 changes: 0 additions & 2 deletions GVFS/GVFS/CommandLine/RepairVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public override void Execute()
{
this.ValidatePathParameter(this.EnlistmentRootPathParameter);

this.CheckGVFSHooksVersion(tracer: null, hooksVersion: out _);

if (!Directory.Exists(this.EnlistmentRootPathParameter))
{
this.ReportErrorAndExit($"Path '{this.EnlistmentRootPathParameter}' does not exist");
Expand Down

0 comments on commit 5b6a1cf

Please sign in to comment.