├── .gitignore ├── LICENSE ├── README.md ├── appveyor.yml ├── build.ps1 ├── gitcloner.csproj ├── install.ps1 ├── packages.config ├── release.ps1 └── src └── gitcloner.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | packages/ 2 | build/ 3 | dist/ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Scoop 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitCloner 2 | 3 | A small script that clones a Git repository to a target directory without requiring a complete installation of Git. 4 | 5 | This is a helper script for [Scoop](https://scoop.sh), the Windows command-line installer. 6 | 7 | # Usage 8 | 9 | ```pwsh 10 | .\gitcloner.ps1 -Repository 'https://github.com///' -Directory '.\test-repo' 11 | ``` 12 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}-{branch}" 2 | image: Visual Studio 2017 3 | 4 | init: 5 | - ps: '(Get-ChildItem -Path "Env:").Where({ $_.Name -match "^(?:BH|CI(?:_|$)|APPVEYOR)" })' 6 | install: 7 | - ps: .\install.ps1 8 | build_script: 9 | - ps: .\build.ps1 10 | after_build: 11 | - ps: .\release.ps1 12 | 13 | artifacts: 14 | - path: 'dist\*' 15 | name: release 16 | 17 | deploy: 18 | description: '$(GITHUB_RELEASE_NOTES)' 19 | provider: GitHub 20 | auth_token: 21 | secure: HmkRazkigvqjOypviF2hyTqwcrLMIC4zAHPUwRfKCi5MnkDHLLnYnOrwDAAtnMvc 22 | artifact: 'release' 23 | draft: false 24 | prerelease: false 25 | on: 26 | branch: master 27 | APPVEYOR_REPO_TAG: true 28 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | Push-Location $PSScriptRoot 2 | 3 | # Prepare 4 | $build = "$PSScriptRoot\build" 5 | $dist = "$PSScriptRoot\dist" 6 | New-Item -ItemType Directory -Path $build -ErrorAction SilentlyContinue | Out-Null 7 | New-Item -ItemType Directory -Path $dist -ErrorAction SilentlyContinue | Out-Null 8 | Remove-Item "$build\*" -Recurse -Force | Out-Null 9 | Remove-Item "$dist\*" -Recurse -Force | Out-Null 10 | 11 | # Build 12 | Copy-Item "$PSScriptRoot\src\gitcloner.ps1" $build 13 | Copy-Item "$PSScriptRoot\packages\LibGit2Sharp\lib\net46\LibGit2Sharp.dll" $build 14 | New-Item -ItemType Directory -Path "$build\lib\win32\x64\" -ErrorAction SilentlyContinue | Out-Null 15 | Copy-Item "$PSScriptRoot\packages\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-*.dll" "$build\lib\win32\x64\" 16 | New-Item -ItemType Directory -Path "$build\lib\win32\x86\" -ErrorAction SilentlyContinue | Out-Null 17 | Copy-Item "$PSScriptRoot\packages\LibGit2Sharp.NativeBinaries\runtimes\win-x86\native\git2-*.dll" "$build\lib\win32\x86\" 18 | 19 | # Checksums 20 | Write-Output 'Computing checksums ...' 21 | Get-ChildItem "$build\*" -Include *.ps1,*.dll -Recurse | ForEach-Object { 22 | $checksum = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash.ToLower() 23 | "$checksum *$($_.FullName.Replace($build, '').TrimStart('\'))" | Tee-Object -FilePath "$build\checksums.sha256" -Append 24 | } 25 | 26 | # Package 27 | 7z a "$dist\gitcloner.zip" "$build\*" 28 | Get-ChildItem "$dist\*" | ForEach-Object { 29 | $checksum = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash.ToLower() 30 | "$checksum *$($_.Name)" | Tee-Object -FilePath "$dist\$($_.Name).sha256" -Append 31 | } 32 | Pop-Location 33 | -------------------------------------------------------------------------------- /gitcloner.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | # https://github.com/edymtt/nugetstandalone 2 | $destinationFolder = "$PSScriptRoot\packages" 3 | if ((Test-Path -path $destinationFolder)) { 4 | Remove-Item -Path $destinationFolder -Recurse | Out-Null 5 | } 6 | 7 | New-Item $destinationFolder -Type Directory | Out-Null 8 | nuget install packages.config -o $destinationFolder -ExcludeVersion 9 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /release.ps1: -------------------------------------------------------------------------------- 1 | if(!$env:APPVEYOR_REPO_TAG) { 2 | return 3 | } 4 | 5 | Write-Output 'Generating release notes ...' 6 | #region GitHub release notes 7 | $previousRelease = (Invoke-RestMethod -Uri "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/releases/latest?access_token=$env:GITHUB_ACCESS_TOKEN" -Verbose) 8 | Write-Host "Previous Release: $($previousRelease.name) ($($previousRelease.target_commitish))" 9 | $compare = (Invoke-RestMethod -Uri "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/compare/$($previousRelease.target_commitish)...$env:APPVEYOR_REPO_COMMIT`?access_token=$env:GITHUB_ACCESS_TOKEN" -Verbose) 10 | $releaseNotes = "## Release Notes`n#### Version [$env:APPVEYOR_REPO_TAG_NAME](https://github.com/$env:APPVEYOR_REPO_NAME/tree/$env:APPVEYOR_REPO_TAG_NAME)`n" 11 | 12 | if($null -ne $compare.commits -and $compare.commits.Length -gt 0) { 13 | $releaseNotes += "`nCommit | Description`n--- | ---`n" 14 | $contributions = @{} 15 | $compare.commits | Sort-Object -Property @{Expression={$_.commit.author.date};} -Descending | ForEach-Object { 16 | $commitMessage = $_.commit.message.Replace("`r`n"," ").Replace("`n"," "); 17 | if ($commitMessage.ToLower().StartsWith('merge') -or 18 | $commitMessage.ToLower().StartsWith('merging') -or 19 | $commitMessage.ToLower().StartsWith('private')) { 20 | continue 21 | } 22 | $releaseNotes += "[``$($_.sha.Substring(0, 7))``](https://github.com/$env:APPVEYOR_REPO_NAME/tree/$($_.sha)) | $commitMessage`n" 23 | $contributions.$($_.author.login)++ 24 | } 25 | $releaseNotes += "`nContributor | Commits`n--- | ---`n" 26 | $contributions.GetEnumerator() | Sort-Object -Property @{Expression={$_.Value}} -Descending | ForEach-Object { 27 | $releaseNotes += "@$($_.Name) | $($_.Value)`n" 28 | } 29 | } else { 30 | $releaseNotes += "There are no new items for this release." 31 | } 32 | 33 | $env:GITHUB_RELEASE_NOTES = $releaseNotes 34 | Write-Output $releaseNotes 35 | #endregion 36 | -------------------------------------------------------------------------------- /src/gitcloner.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Clones a Git repository to target directory 4 | .DESCRIPTION 5 | A small script that clones a Git repository to a target directory without requiring a complete installation of Git. 6 | .PARAMETER Repository 7 | Valid Git repository URL or Path 8 | .PARAMETER Dir 9 | Target directory where the repository gets cloned to 10 | .EXAMPLE 11 | PS > .\gitcloner.ps1 -Repository 'https://github.com///' -Directory '.\test-clone' 12 | #> 13 | param( 14 | [Parameter(Mandatory = $true, Position = 0)] 15 | [String] $Repository, 16 | [Parameter(Mandatory = $true, Position = 1)] 17 | [String] $Directory 18 | ) 19 | 20 | Add-Type -TypeDefinition @" 21 | using System; 22 | using System.Diagnostics; 23 | using System.Runtime.InteropServices; 24 | 25 | public static class Kernel32 26 | { 27 | [DllImport("kernel32", SetLastError=true, CharSet = CharSet.Ansi)] 28 | public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName); 29 | } 30 | "@ 31 | 32 | 33 | if([System.IntPtr]::Size -eq 8) { 34 | [Kernel32]::LoadLibrary((Get-ChildItem "$PSScriptRoot\lib\win32\x64\git2-???????.dll" | Select-Object -First 1).FullName) | Out-Null 35 | } else { 36 | [Kernel32]::LoadLibrary((Get-ChildItem "$PSScriptRoot\lib\win32\x86\git2-???????.dll" | Select-Object -First 1).FullName) | Out-Null 37 | } 38 | 39 | Add-Type -Path "$PSScriptRoot\LibGit2Sharp.dll" 40 | 41 | try { 42 | [LibGit2Sharp.Repository]::Clone($Repository, $Directory) 43 | exit 0 44 | } catch [Exception] { 45 | Write-Output $_.Exception.Message 46 | exit 1 47 | } 48 | --------------------------------------------------------------------------------