Skip to content

Commit

Permalink
Merge pull request #1351 No longer set PATH for git process and remov…
Browse files Browse the repository at this point in the history
…e use of gvfs hooks root

No longer set PATH for git process and remove use of gvfs hooks root
  • Loading branch information
Kevin Willford authored Aug 2, 2019
2 parents e315c6c + ed150e2 commit 34ed486
Show file tree
Hide file tree
Showing 24 changed files with 35 additions and 88 deletions.
1 change: 0 additions & 1 deletion GVFS/FastFetch/GitEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ private GitEnlistment(string repoRoot, string gitBinPath)
repoRoot,
null,
gitBinPath,
gvfsHooksRoot: null,
flushFileBuffersForPacks: false,
authentication: null)
{
Expand Down
1 change: 0 additions & 1 deletion GVFS/GVFS.Common/DiskLayoutUpgrades/DiskLayoutUpgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ protected bool TrySetGitConfig(ITracer tracer, string enlistmentRoot, Dictionary
enlistment = GVFSEnlistment.CreateFromDirectory(
enlistmentRoot,
GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath(),
ProcessHelper.GetCurrentProcessLocation(),
authentication: null);
}
catch (InvalidRepoException e)
Expand Down
3 changes: 0 additions & 3 deletions GVFS/GVFS.Common/Enlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ protected Enlistment(
string workingDirectoryBackingRoot,
string repoUrl,
string gitBinPath,
string gvfsHooksRoot,
bool flushFileBuffersForPacks,
GitAuthentication authentication)
{
Expand All @@ -27,7 +26,6 @@ protected Enlistment(
this.WorkingDirectoryBackingRoot = workingDirectoryBackingRoot;
this.DotGitRoot = Path.Combine(this.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Root);
this.GitBinPath = gitBinPath;
this.GVFSHooksRoot = gvfsHooksRoot;
this.FlushFileBuffersForPacks = flushFileBuffersForPacks;

GitProcess gitProcess = new GitProcess(this);
Expand Down Expand Up @@ -72,7 +70,6 @@ protected Enlistment(
public bool FlushFileBuffersForPacks { get; }

public string GitBinPath { get; }
public string GVFSHooksRoot { get; }

public GitAuthentication Authentication { get; }

Expand Down
11 changes: 4 additions & 7 deletions GVFS/GVFS.Common/GVFSEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ public partial class GVFSEnlistment : Enlistment
private string gvfsHooksVersion;

// New enlistment
public GVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, string gvfsHooksRoot, GitAuthentication authentication)
public GVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, GitAuthentication authentication)
: base(
enlistmentRoot,
Path.Combine(enlistmentRoot, GVFSConstants.WorkingDirectoryRootName),
Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.WorkingDirectoryBackingRootPath),
repoUrl,
gitBinPath,
gvfsHooksRoot,
flushFileBuffersForPacks: true,
authentication: authentication)
{
Expand All @@ -40,12 +39,11 @@ public GVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath,
}

// Existing, configured enlistment
private GVFSEnlistment(string enlistmentRoot, string gitBinPath, string gvfsHooksRoot, GitAuthentication authentication)
private GVFSEnlistment(string enlistmentRoot, string gitBinPath, GitAuthentication authentication)
: this(
enlistmentRoot,
null,
gitBinPath,
gvfsHooksRoot,
authentication)
{
}
Expand Down Expand Up @@ -85,7 +83,6 @@ public string GVFSHooksVersion
public static GVFSEnlistment CreateFromDirectory(
string directory,
string gitBinRoot,
string gvfsHooksRoot,
GitAuthentication authentication,
bool createWithoutRepoURL = false)
{
Expand All @@ -100,10 +97,10 @@ public static GVFSEnlistment CreateFromDirectory(

if (createWithoutRepoURL)
{
return new GVFSEnlistment(enlistmentRoot, string.Empty, gitBinRoot, gvfsHooksRoot, authentication);
return new GVFSEnlistment(enlistmentRoot, string.Empty, gitBinRoot, authentication);
}

return new GVFSEnlistment(enlistmentRoot, gitBinRoot, gvfsHooksRoot, authentication);
return new GVFSEnlistment(enlistmentRoot, gitBinRoot, authentication);
}

throw new InvalidRepoException($"Directory '{directory}' does not exist");
Expand Down
5 changes: 1 addition & 4 deletions GVFS/GVFS.Common/GVFSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void Register(GVFSPlatform platform)

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

public abstract bool TryGetGVFSHooksPathAndVersion(out string hooksPaths, out string hooksVersion, out string error);
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);
Expand Down Expand Up @@ -206,18 +206,15 @@ public class UnderConstructionFlags
public UnderConstructionFlags(
bool supportsGVFSUpgrade = true,
bool supportsGVFSConfig = true,
bool requiresDeprecatedGitHooksLoader = false,
bool supportsNuGetEncryption = true)
{
this.SupportsGVFSUpgrade = supportsGVFSUpgrade;
this.SupportsGVFSConfig = supportsGVFSConfig;
this.RequiresDeprecatedGitHooksLoader = requiresDeprecatedGitHooksLoader;
this.SupportsNuGetEncryption = supportsNuGetEncryption;
}

public bool SupportsGVFSUpgrade { get; }
public bool SupportsGVFSConfig { get; }
public bool RequiresDeprecatedGitHooksLoader { get; }
public bool SupportsNuGetEncryption { get; }
}
}
Expand Down
19 changes: 6 additions & 13 deletions GVFS/GVFS.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class GitProcess : ICredentialStore
private string gitBinPath;
private string workingDirectoryRoot;
private string dotGitRoot;
private string gvfsHooksRoot;
private Process executingProcess;
private bool stopping;

Expand Down Expand Up @@ -62,11 +61,11 @@ static GitProcess()
}

public GitProcess(Enlistment enlistment)
: this(enlistment.GitBinPath, enlistment.WorkingDirectoryBackingRoot, enlistment.GVFSHooksRoot)
: this(enlistment.GitBinPath, enlistment.WorkingDirectoryBackingRoot)
{
}

public GitProcess(string gitBinPath, string workingDirectoryRoot, string gvfsHooksRoot)
public GitProcess(string gitBinPath, string workingDirectoryRoot)
{
if (string.IsNullOrWhiteSpace(gitBinPath))
{
Expand All @@ -75,7 +74,6 @@ public GitProcess(string gitBinPath, string workingDirectoryRoot, string gvfsHoo

this.gitBinPath = gitBinPath;
this.workingDirectoryRoot = workingDirectoryRoot;
this.gvfsHooksRoot = gvfsHooksRoot;

if (this.workingDirectoryRoot != null)
{
Expand All @@ -93,27 +91,27 @@ public static Result Init(Enlistment enlistment)
public static ConfigResult GetFromGlobalConfig(string gitBinPath, string settingName)
{
return new ConfigResult(
new GitProcess(gitBinPath, workingDirectoryRoot: null, gvfsHooksRoot: null).InvokeGitOutsideEnlistment("config --global " + settingName),
new GitProcess(gitBinPath, workingDirectoryRoot: null).InvokeGitOutsideEnlistment("config --global " + settingName),
settingName);
}

public static ConfigResult GetFromSystemConfig(string gitBinPath, string settingName)
{
return new ConfigResult(
new GitProcess(gitBinPath, workingDirectoryRoot: null, gvfsHooksRoot: null).InvokeGitOutsideEnlistment("config --system " + settingName),
new GitProcess(gitBinPath, workingDirectoryRoot: null).InvokeGitOutsideEnlistment("config --system " + settingName),
settingName);
}

public static ConfigResult GetFromFileConfig(string gitBinPath, string configFile, string settingName)
{
return new ConfigResult(
new GitProcess(gitBinPath, workingDirectoryRoot: null, gvfsHooksRoot: null).InvokeGitOutsideEnlistment("config --file " + configFile + " " + settingName),
new GitProcess(gitBinPath, workingDirectoryRoot: null).InvokeGitOutsideEnlistment("config --file " + configFile + " " + settingName),
settingName);
}

public static bool TryGetVersion(string gitBinPath, out GitVersion gitVersion, out string error)
{
GitProcess gitProcess = new GitProcess(gitBinPath, null, null);
GitProcess gitProcess = new GitProcess(gitBinPath, null);
Result result = gitProcess.InvokeGitOutsideEnlistment("--version");
string version = result.Output;

Expand Down Expand Up @@ -683,11 +681,6 @@ public Process GetGitProcess(string command, string workingDirectory, string dot

processInfo.EnvironmentVariables["GIT_TERMINAL_PROMPT"] = "0";
processInfo.EnvironmentVariables["GCM_VALIDATE"] = "0";
processInfo.EnvironmentVariables["PATH"] =
string.Join(
";",
this.gitBinPath,
this.gvfsHooksRoot ?? string.Empty);

if (gitObjectsDirectory != null)
{
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Mount/InProcessMountVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private GVFSEnlistment CreateEnlistment(string enlistmentRootPath)
GVFSEnlistment enlistment = null;
try
{
enlistment = GVFSEnlistment.CreateFromDirectory(enlistmentRootPath, gitBinPath, ProcessHelper.GetCurrentProcessLocation(), authentication: null);
enlistment = GVFSEnlistment.CreateFromDirectory(enlistmentRootPath, gitBinPath, authentication: null);
}
catch (InvalidRepoException e)
{
Expand Down
4 changes: 1 addition & 3 deletions GVFS/GVFS.PerfProfiling/ProfilingEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public ProfilingEnvironment(string enlistmentRootPath)
private GVFSEnlistment CreateEnlistment(string enlistmentRootPath)
{
string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();
string hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);

return GVFSEnlistment.CreateFromDirectory(enlistmentRootPath, gitBinPath, hooksPath, authentication: null);
return GVFSEnlistment.CreateFromDirectory(enlistmentRootPath, gitBinPath, authentication: null);
}

private GVFSContext CreateContext()
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Platform.Mac/MacPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override string GetUpgradeHighestAvailableVersionDirectory()
/// <summary>
/// This is the directory in which the upgradelogs directory should go.
/// There can be multiple logs directories, so here we return the containing
// directory.
/// directory.
/// </summary>
public override string GetUpgradeLogDirectoryParentDirectory()
{
Expand Down
9 changes: 1 addition & 8 deletions GVFS/GVFS.Platform.POSIX/POSIXPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
{
}

public override bool TryGetGVFSHooksPathAndVersion(out string hooksPaths, out string hooksVersion, out string error)
public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string error)
{
hooksPaths = string.Empty;
string binPath = Path.Combine(this.Constants.GVFSBinDirectoryPath, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
if (File.Exists(binPath))
{
hooksPaths = binPath;
}

// TODO(#1044): Get the hooks version rather than the GVFS version (and share that code with the Windows platform)
hooksVersion = ProcessHelper.GetCurrentProcessVersion();
error = null;
Expand Down
6 changes: 3 additions & 3 deletions GVFS/GVFS.Platform.Windows/WindowsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class WindowsPlatform : GVFSPlatform
private const string BuildLabRegistryValue = "BuildLab";
private const string BuildLabExRegistryValue = "BuildLabEx";

public WindowsPlatform() : base(underConstruction: new UnderConstructionFlags(requiresDeprecatedGitHooksLoader: true))
public WindowsPlatform() : base(underConstruction: new UnderConstructionFlags())
{
}

Expand Down Expand Up @@ -256,11 +256,11 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
}
}

public override bool TryGetGVFSHooksPathAndVersion(out string hooksPath, out string hooksVersion, out string error)
public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string error)
{
error = null;
hooksVersion = null;
hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
string hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
if (hooksPath == null)
{
error = "Could not find " + GVFSPlatform.Instance.Constants.GVFSHooksExecutableName;
Expand Down
7 changes: 2 additions & 5 deletions GVFS/GVFS.Service/Handlers/GetActiveRepoListHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,23 @@ public void Run()
private bool IsValidRepo(string repoRoot)
{
string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();
string hooksPath = null;

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

Expand All @@ -97,7 +94,7 @@ private bool IsValidRepo(string repoRoot)
}
else
{
this.tracer.RelatedError($"{nameof(this.IsValidRepo)}: {nameof(GVFSPlatform.Instance.TryGetGVFSHooksPathAndVersion)} failed. {error}");
this.tracer.RelatedError($"{nameof(this.IsValidRepo)}: {nameof(GVFSPlatform.Instance.TryGetGVFSHooksVersion)} failed. {error}");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Common/GVFSEnlistmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private class TestGVFSEnlistment : GVFSEnlistment
private MockGitProcess gitProcess;

public TestGVFSEnlistment()
: base("mock:\\path", "mock://repoUrl", "mock:\\git", gvfsHooksRoot: null, authentication: null)
: base("mock:\\path", "mock://repoUrl", "mock:\\git", authentication: null)
{
this.gitProcess = new MockGitProcess();
this.gitProcess.SetExpectedCommandResult(
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void SetUp()

this.gitProcess = new MockGitProcess();
this.gitProcess.SetExpectedCommandResult($"--no-optional-locks status \"--serialize={statusCachePath}", () => new GitProcess.Result(string.Empty, string.Empty, 0), true);
MockGVFSEnlistment enlistment = new MockGVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", null, this.gitProcess);
MockGVFSEnlistment enlistment = new MockGVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", this.gitProcess);
enlistment.InitializeCachePathsFromKey("fake:\\gvfsSharedCache", "fakeCacheKey");

this.gitParentPath = enlistment.WorkingDirectoryBackingRoot;
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Git/GVFSGitObjectsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void AssertRetryableExceptionOnDownload(
private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects, MockFileSystemWithCallbacks fileSystem)
{
MockTracer tracer = new MockTracer();
GVFSEnlistment enlistment = new GVFSEnlistment(TestEnlistmentRoot, "https://fakeRepoUrl", "fakeGitBinPath", gvfsHooksRoot: null, authentication: null);
GVFSEnlistment enlistment = new GVFSEnlistment(TestEnlistmentRoot, "https://fakeRepoUrl", "fakeGitBinPath", authentication: null);
enlistment.InitializeCachePathsFromKey(TestLocalCacheRoot, TestObjectRoot);
GitRepo repo = new GitRepo(tracer, enlistment, fileSystem, () => new MockLibGit2Repo(tracer));

Expand Down
6 changes: 3 additions & 3 deletions GVFS/GVFS.UnitTests/Mock/Common/MockGVFSEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class MockGVFSEnlistment : GVFSEnlistment
private MockGitProcess gitProcess;

public MockGVFSEnlistment()
: base(Path.Combine("mock:", "path"), "mock://repoUrl", Path.Combine("mock:", "git"), gvfsHooksRoot: null, authentication: null)
: base(Path.Combine("mock:", "path"), "mock://repoUrl", Path.Combine("mock:", "git"), authentication: null)
{
this.GitObjectsRoot = Path.Combine("mock:", "path", ".git", "objects");
this.LocalObjectsRoot = this.GitObjectsRoot;
this.GitPackRoot = Path.Combine("mock:", "path", ".git", "objects", "pack");
}

public MockGVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, string gvfsHooksRoot, MockGitProcess gitProcess)
: base(enlistmentRoot, repoUrl, gitBinPath, gvfsHooksRoot, authentication: null)
public MockGVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath, MockGitProcess gitProcess)
: base(enlistmentRoot, repoUrl, gitBinPath, authentication: null)
{
this.gitProcess = gitProcess;
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Mock/Common/MockPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
throw new NotSupportedException();
}

public override bool TryGetGVFSHooksPathAndVersion(out string hooksPaths, out string hooksVersion, out string error)
public override bool TryGetGVFSHooksVersion(out string hooksVersion, out string error)
{
throw new NotSupportedException();
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Virtual/CommonRepoSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public CommonRepoSetup()
MockTracer tracer = new MockTracer();

string enlistmentRoot = Path.Combine("mock:", "GVFS", "UnitTests", "Repo");
GVFSEnlistment enlistment = new GVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", gvfsHooksRoot: null, authentication: null);
GVFSEnlistment enlistment = new GVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", authentication: null);
enlistment.InitializeCachePathsFromKey("fake:\\gvfsSharedCache", "fakeCacheKey");

this.GitParentPath = enlistment.WorkingDirectoryRoot;
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Upgrader/UpgradeOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private bool TryInitialize(out string errorMessage)
return false;
}

ICredentialStore credentialStore = new GitProcess(gitBinPath, workingDirectoryRoot: null, gvfsHooksRoot: null);
ICredentialStore credentialStore = new GitProcess(gitBinPath, workingDirectoryRoot: null);

ProductUpgrader upgrader;
if (!ProductUpgrader.TryCreateUpgrader(this.tracer, this.fileSystem, new LocalGVFSConfig(), credentialStore, this.DryRun, this.NoVerify, out upgrader, out errorMessage))
Expand Down
Loading

0 comments on commit 34ed486

Please sign in to comment.