Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the full path to GVFS.Hooks executable in the hook configuration #1487

Merged
merged 2 commits into from
Aug 24, 2019
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
7 changes: 4 additions & 3 deletions GVFS/GVFS.Common/FileSystem/HooksInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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);

if (valuableHooksLines.Contains(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName, GVFSPlatform.Instance.Constants.PathComparer))
{
Expand All @@ -37,15 +38,15 @@ public static string MergeHooksData(string[] defaultHooksLines, string filename,
}
else if (!valuableHooksLines.Any())
{
return GVFSPlatform.Instance.Constants.GVFSHooksExecutableName;
return absolutePathToHooksExecutable;
}
else if (hookName.Equals(GVFSConstants.DotGit.Hooks.PostCommandHookName))
{
return string.Join("\n", new string[] { GVFSPlatform.Instance.Constants.GVFSHooksExecutableName }.Concat(valuableHooksLines));
return string.Join("\n", new string[] { absolutePathToHooksExecutable }.Concat(valuableHooksLines));
}
else
{
return string.Join("\n", valuableHooksLines.Concat(new string[] { GVFSPlatform.Instance.Constants.GVFSHooksExecutableName }));
return string.Join("\n", valuableHooksLines.Concat(new string[] { absolutePathToHooksExecutable }));
}
}

Expand Down
16 changes: 11 additions & 5 deletions GVFS/GVFS.UnitTests/CommandLine/HooksInstallerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

namespace GVFS.UnitTests.CommandLine
{
[TestFixture]
public class HooksInstallerTests
{
private const string Filename = "hooksfile";
private readonly string expectedAbsoluteGvfsHookPath =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);

[TestCase]
[Category(CategoryConstants.ExceptionExpected)]
Expand All @@ -22,7 +28,7 @@ public void MergeHooksDataThrowsOnFoundGVFSHooks()
() => HooksInstaller.MergeHooksData(
new string[] { "first", GVFSPlatform.Instance.Constants.GVFSHooksExecutableName },
Filename,
GVFSConstants.DotGit.Hooks.PreCommandHookName));
this.expectedAbsoluteGvfsHookPath));
}

[TestCase]
Expand All @@ -33,7 +39,7 @@ public void MergeHooksDataEmptyConfig()
.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
.Where(line => !line.StartsWith("#"));

resultLines.Single().ShouldEqual(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
resultLines.Single().ShouldEqual(this.expectedAbsoluteGvfsHookPath);
}

[TestCase]
Expand All @@ -47,7 +53,7 @@ public void MergeHooksDataPreCommandLast()
resultLines.Count().ShouldEqual(3);
resultLines.ElementAt(0).ShouldEqual("first");
resultLines.ElementAt(1).ShouldEqual("second");
resultLines.ElementAt(2).ShouldEqual(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
resultLines.ElementAt(2).ShouldEqual(this.expectedAbsoluteGvfsHookPath);
}

[TestCase]
Expand All @@ -59,7 +65,7 @@ public void MergeHooksDataPostCommandFirst()
.Where(line => !line.StartsWith("#"));

resultLines.Count().ShouldEqual(3);
resultLines.ElementAt(0).ShouldEqual(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
resultLines.ElementAt(0).ShouldEqual(this.expectedAbsoluteGvfsHookPath);
resultLines.ElementAt(1).ShouldEqual("first");
resultLines.ElementAt(2).ShouldEqual("second");
}
Expand All @@ -75,7 +81,7 @@ public void MergeHooksDataDiscardBlankLines()
resultLines.Count().ShouldEqual(3);
resultLines.ElementAt(0).ShouldEqual("first");
resultLines.ElementAt(1).ShouldEqual("second");
resultLines.ElementAt(2).ShouldEqual(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
resultLines.ElementAt(2).ShouldEqual(this.expectedAbsoluteGvfsHookPath);
}
}
}