felixfbecker / PowerGit

Git with the power of the PowerShell object pipeline. For macOS, Linux and Windows.
Apache License 2.0
30 stars 6 forks source link

[BUG] versions > 0.7.1 Copy-GitRepository error #35

Open user8446 opened 2 years ago

user8446 commented 2 years ago

@felixfbecker Hello,

After the 0.8.1 update Copy-GitRepository throws:

MethodInvocationException: C:\Users\###\Documents\PowerShell\Modules\PowerGit\0.8.1\Functions\Copy-GitRepository.ps1:152:13
Line |
 152 |              $gitPath = [LibGit2Sharp.Repository]::Clone($Source, $Des …
        |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        | Exception calling "Clone" with "3" argument(s): "The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception."

Downgrading to 0.7.1 works as expected

Edit: Repro'ed with all versions after 0.8.1 as well

ThomasNieto commented 2 years ago

This is due to an issue with the module being deployed with a file called installed. The module uses that file to indicate if the required platform specific binary has been copied to the correct location. Right now, the MacOS version is present causing issues on Windows. If you run this command it will remove the bad files so it can import correctly.

$module = Get-Module PowerGit -ListAvailable | sort version -Descending | select -exp modulebase -First 1
rm $module\Assemblies\installed, $module\Assemblies\libgit2-*

@felixfbecker can we please get this resolved? Instead of copying the file in the appropriate place PowerShell 7 added a unmanaged native library resolver that handles this work for you. Here is the link for more information: https://docs.microsoft.com/en-us/powershell/scripting/dev-cross-plat/writing-portable-modules?view=powershell-7.2#dependency-on-native-libraries

user8446 commented 2 years ago

Just want to say thanks for researching and the workaround @ThomasNieto