Skip to content

Commit

Permalink
Merge pull request #1487: Use the full path to GVFS.Hooks executable …
Browse files Browse the repository at this point in the history
…in the hook configuration
  • Loading branch information
jrbriggs authored Aug 24, 2019
2 parents 993b69d + 33d723c commit 6446823
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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);
}
}
}

0 comments on commit 6446823

Please sign in to comment.