Skip to content

Commit e156d58

Browse files
authored
Merge pull request #47 from lekhmanrus/hooks-outside-git-folder
Fix hooks folder location
2 parents 5e95991 + a779697 commit e156d58

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/GitExtensions.GerritPlugin/GerritPlugin.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ private static bool HasValidCommitMsgHook([NotNull] IGitModule gitModule, bool f
166166

167167
private static string GetCommitMessageHookPath([NotNull] IGitModule gitModule)
168168
{
169-
return Path.Combine(gitModule.ResolveGitInternalPath(HooksFolderName), CommitMessageHookFileName);
169+
var hooksAbsolutePath = gitModule.ResolveGitInternalPath(HooksFolderName);
170+
// because hooks folder could be outside of .git folder (e.g. .husky)
171+
if (!Path.IsPathRooted(hooksAbsolutePath))
172+
{
173+
hooksAbsolutePath = Path.Combine(gitModule.WorkingDir, hooksAbsolutePath);
174+
}
175+
176+
return Path.Combine(hooksAbsolutePath, CommitMessageHookFileName);
170177
}
171178

172179
private void Initialize(Form form)
@@ -333,7 +340,8 @@ private async Task InstallCommitMsgHookAsync()
333340
return;
334341
}
335342

336-
var hooksFolderPath = _gitUiCommands.GitModule.ResolveGitInternalPath(HooksFolderName);
343+
var commitMessageHookPath = GetCommitMessageHookPath(_gitUiCommands.GitModule);
344+
var hooksFolderPath = Path.GetDirectoryName(commitMessageHookPath);
337345
if (!Directory.Exists(hooksFolderPath))
338346
{
339347
try
@@ -353,10 +361,7 @@ private async Task InstallCommitMsgHookAsync()
353361
}
354362
}
355363

356-
var commitMessageHookPath = Path.Combine(hooksFolderPath, CommitMessageHookFileName);
357-
358364
string content;
359-
360365
try
361366
{
362367
content = await DownloadFromScpAsync(settings);

0 commit comments

Comments
 (0)