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

Husky throws an ArgumentException when I try to commit through Sourcetree #96

Closed
zero-point-one-x-engineer opened this issue Nov 13, 2023 · 5 comments
Labels
bug Something isn't working fixed

Comments

@zero-point-one-x-engineer

Version

0.6.2

Details

I am not so sure if this should be opened as a bug or a discussion would be a better fit so apologies in advance but basically
whenever I try to commit changes through Sourcetree Husky throws an ArgumentException.

husky-exception

Here's the stack trace:

Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: HOME
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at CliFx.Utils.Extensions.CollectionExtensions.ToDictionary[TKey,TValue](IDictionary dictionary, IEqualityComparer`1 comparer) in /_/CliFx/Utils/Extensions/CollectionExtensions.cs:line 38
   at CliFx.CliApplication.RunAsync(IReadOnlyList`1 commandLineArguments) in /_/CliFx/CliApplication.cs:line 216
   at Program.<Main>$(String[] args) in /home/runner/work/Husky.Net/Husky.Net/src/Husky/Program.cs:line 31
   at Program.<Main>(String[] args)

It works as expected if I try to commit either from the CLI, VS or VSCode but not on Sourcetree. I had a very quick look at the source code to try and figure out what could be happening but couldn't figure anything out immediately. Any idea what that Key: HOME might be or where it comes from? is it an environment variable? I'd appreciate any feedback on this, we'd really like to use your tool but without having to sacrificing Sourcetree in the process 😄. Thanks!

OS: Windows 11 Pro 22621.2428
Sourcetree version: 3.4.15

Steps to reproduce

@zero-point-one-x-engineer zero-point-one-x-engineer added the bug Something isn't working label Nov 13, 2023
@alirezanet alirezanet removed the bug Something isn't working label Nov 13, 2023
@alirezanet
Copy link
Owner

alirezanet commented Nov 13, 2023

Hi @AntonisManiatis,
I think for some reason sourcetree is sending additional arguments to the hooks! (I never used this app before so I need to research what it is doing)
can you share your git and credential manager versions?

image

Also, please check your Environment variables, This might imply you have two identical environment variables (on Windows that also ignores casing)

@zero-point-one-x-engineer
Copy link
Author

Hi @alirezanet,

Here's my git & git credential-manager versions:

image

I checked my environment variables and nothing seems out of the ordinary, no duplicates etc. Also a colleague of mine tried on his machine (again windows 11 & latest Sourcetree) and it's the same story.

I wrote a little program to print command line arguments and environment variables to standard out, changed the pre-commit hook to call that program instead of doing dotnet husky run --group pre-commit , commited a change through Sourcetree and I didn't find any duplicate env variables printed.

@alirezanet
Copy link
Owner

alirezanet commented Nov 14, 2023

Hi @AntonisManiatis,
I found the problem, for some reason, Sourcetree is adding a lower-case home environment variable and that is causing the issue, I'm working on a fix for this issue here...
if you want to also test it you can change your pre-commit hook to log the environment variables this way if you want:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# Log all environment variables
printenv

dotnet husky run -v --group "pre-commit"

more info: https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

@alirezanet alirezanet added the bug Something isn't working label Nov 14, 2023
@alirezanet
Copy link
Owner

Hi @AntonisManiatis,
This is fixed in v0.6.3.

@zero-point-one-x-engineer
Copy link
Author

thank you very much @alirezanet, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants