Skip to content
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
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions .husky/task-runner.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"variables": [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this test variable is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored in commit 6ecc630. Updated to use cross-platform commands (bash -c ls instead of cmd /c dir /b) to work on Linux/CI environments.

{
"name": "root-dir",
"command": "cmd",
"args": ["/c", "dir", "/b"]
"command": "bash",
"args": ["-c", "pwd"]
}
],
"tasks": [
Expand All @@ -19,11 +19,11 @@
"args" :["husky", "exec", ".husky/csx/version-updater.csx", "--args", "${args}"]
},
{
"name": "echo staged files",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this test task is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored in commit 6ecc630. Updated to use cross-platform echo command instead of cmd /c echo to work on Linux/CI environments.

"name": "echo-staged-files",
"pathMode": "absolute",
"command": "cmd",
"command": "echo",
"group": "pre-commit",
"args": [ "/c", "echo", "${staged}"]
"args": ["${staged}"]
}
]
}
2 changes: 2 additions & 0 deletions src/Husky/Services/Contracts/ICliWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace Husky.Services.Contracts;
public interface ICliWrap
{
Task<BufferedCommandResult> ExecBufferedAsync(string fileName, string args);
Task<BufferedCommandResult> ExecBufferedAsync(string fileName, IEnumerable<string> args);
ValueTask SetExecutablePermission(params string[] files);
Task<CommandResult> ExecDirectAsync(string fileName, string args);
Task<CommandResult> ExecDirectAsync(string fileName, IEnumerable<string> args);

Task<CommandResult> RunCommandAsync(string fileName, IEnumerable<string> args, string cwd,
OutputTypes output = OutputTypes.Verbose);
Expand Down
2 changes: 2 additions & 0 deletions src/Husky/Services/Contracts/IGit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public interface IGit
/// <returns></returns>
Task<string[]> GetDiffStagedRecord();
Task<CommandResult> ExecAsync(string args);
Task<CommandResult> ExecAsync(IEnumerable<string> args);
Task<BufferedCommandResult> ExecBufferedAsync(string args);
Task<BufferedCommandResult> ExecBufferedAsync(IEnumerable<string> args);
}
10 changes: 10 additions & 0 deletions src/Husky/Services/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,21 @@ public Task<CommandResult> ExecAsync(string args)
return _cliWrap.ExecDirectAsync("git", args);
}

public Task<CommandResult> ExecAsync(IEnumerable<string> args)
{
return _cliWrap.ExecDirectAsync("git", args);
}

public Task<BufferedCommandResult> ExecBufferedAsync(string args)
{
return _cliWrap.ExecBufferedAsync("git", args);
}

public Task<BufferedCommandResult> ExecBufferedAsync(IEnumerable<string> args)
{
return _cliWrap.ExecBufferedAsync("git", args);
}

private async Task<string> GetHuskyPath()
{
try
Expand Down
29 changes: 29 additions & 0 deletions src/Husky/Services/HuskyCliWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ public async Task<BufferedCommandResult> ExecBufferedAsync(string fileName, stri
}
}

public async Task<BufferedCommandResult> ExecBufferedAsync(string fileName, IEnumerable<string> args)
{
try
{
var result = await CliWrap.Cli
.Wrap(fileName)
.WithArguments(args)
.ExecuteBufferedAsync();
return result;
}
catch (Exception)
{
$"failed to execute command '{fileName}'".LogErr();
throw;
}
}
Comment on lines +29 to +44
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecBufferedAsync(string fileName, IEnumerable<string> args) duplicates the implementation of the existing ExecBufferedAsync(string fileName, string args) method. To reduce maintenance overhead and keep behavior perfectly in sync, consider centralizing the implementation (e.g., implement one overload in terms of the other or extract a private helper).

Copilot uses AI. Check for mistakes.

public async ValueTask SetExecutablePermission(params string[] files)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down Expand Up @@ -53,6 +70,18 @@ public async Task<CommandResult> ExecDirectAsync(string fileName, string args)
return result;
}

public async Task<CommandResult> ExecDirectAsync(string fileName, IEnumerable<string> args)
{
var result = await CliWrap.Cli
.Wrap(fileName)
.WithArguments(args)
.WithValidation(CommandResultValidation.None)
.WithStandardOutputPipe(PipeTarget.ToDelegate(q => q.Log()))
.WithStandardErrorPipe(PipeTarget.ToDelegate(q => q.LogErr()))
.ExecuteAsync();
return result;
}

public async Task<CommandResult> RunCommandAsync(
string fileName,
IEnumerable<string> args,
Expand Down
12 changes: 7 additions & 5 deletions src/Husky/TaskRunner/StagedTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using CliFx.Exceptions;
using Husky.Services.Contracts;
Expand Down Expand Up @@ -107,7 +106,7 @@
foreach (var tf in tmpFiles)
{
// add formatted temp file to git database
var result = await _git.ExecBufferedAsync($"hash-object -w {tf.tmp_path}");
var result = await _git.ExecBufferedAsync(new[] { "hash-object", "-w", tf.tmp_path });

Check warning on line 109 in src/Husky/TaskRunner/StagedTask.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'temporaryFile' in 'TemporaryFile.implicit operator string(TemporaryFile temporaryFile)'.

Check warning on line 109 in src/Husky/TaskRunner/StagedTask.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'temporaryFile' in 'TemporaryFile.implicit operator string(TemporaryFile temporaryFile)'.

Check warning on line 109 in src/Husky/TaskRunner/StagedTask.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'temporaryFile' in 'TemporaryFile.implicit operator string(TemporaryFile temporaryFile)'.

Check warning on line 109 in src/Husky/TaskRunner/StagedTask.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'temporaryFile' in 'TemporaryFile.implicit operator string(TemporaryFile temporaryFile)'.

Check warning on line 109 in src/Husky/TaskRunner/StagedTask.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'temporaryFile' in 'TemporaryFile.implicit operator string(TemporaryFile temporaryFile)'.

Check warning on line 109 in src/Husky/TaskRunner/StagedTask.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'temporaryFile' in 'TemporaryFile.implicit operator string(TemporaryFile temporaryFile)'.
var newHash = result.StandardOutput.Trim();

// check if the partial hash exists
Expand All @@ -122,7 +121,7 @@
{
$"Updating index entry for {tf.src_path}".LogVerbose();
await _git.ExecAsync(
$"update-index --cacheinfo {tf.dst_mode},{newHash},{tf.src_path}"
new[] { "update-index", "--cacheinfo", $"{tf.dst_mode},{newHash},{tf.src_path}" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use new c# syntax with: [] instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in commit 6ecc630. Now using C# 12 collection expression syntax: List<string> gitAddArgs = ["add", ..stagedFiles];

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it resolved in line 124

);
}
else
Expand All @@ -143,14 +142,17 @@
.OfType<FileArgumentInfo>()
.Where(q => q.ArgumentTypes == ArgumentTypes.StagedFile)
.Except(partialStagedFiles)
.Select(q => !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"\"{q.RelativePath}\"" : $"\"{q.RelativePath.Replace("/", @"\")}\"")
.Select(q => q.RelativePath)
.ToList();

if (stagedFiles.Any())
{
"Re-staging staged files...".LogVerbose();
string.Join(Environment.NewLine, stagedFiles).LogVerbose();
await _git.ExecAsync($"add {string.Join(" ", stagedFiles)}");

// Build git add command with file paths as separate arguments
List<string> gitAddArgs = ["add", ..stagedFiles];
await _git.ExecAsync(gitAddArgs);
}
}

Expand Down
Loading
Loading