From 0bb7dba477e77eb56b8670c5c5cd8254e67b0231 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz <markus@fleschutz.de> Date: Fri, 21 Jan 2022 20:04:05 +0100 Subject: [PATCH] Update clone-repos.ps1 --- Scripts/clone-repos.ps1 | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Scripts/clone-repos.ps1 b/Scripts/clone-repos.ps1 index efdb222f..d7e1eb0c 100755 --- a/Scripts/clone-repos.ps1 +++ b/Scripts/clone-repos.ps1 @@ -6,50 +6,55 @@ .PARAMETER folder Specifies the target folder .EXAMPLE - PS> ./clone-repos C:\Users\Markus\Repos + PS> ./clone-repos C:\Repos .NOTES - Author: Markus Fleschutz ยท License: CC0 + Author: Markus Fleschutz / License: CC0 .LINK https://github.com/fleschutz/PowerShell #> -param([string]$folder = "$PWD") +param([string]$FolderPath = "$PWD") try { $StopWatch = [system.diagnostics.stopwatch]::startNew() - if (-not(test-path "$folder" -pathType container)) { throw "Can't access directory: $folder" } + if (-not(test-path "$FolderPath" -pathType container)) { throw "Can't access directory: $FolderPath" } + $ParentFolderName = (get-item "$FolderPath").Name $Null = (git --version) if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } $Table = import-csv "$PSScriptRoot/../Data/git-repos.csv" - $TableCount = $Table.count - "Found $TableCount entries in Data/git-repos.csv database..." + $NumEntries = $Table.count + "Found $NumEntries entries in database Data/git-repos.csv..." - [int]$Count = 0 + [int]$Step = 0 + [int]$Cloned = 0 + [int]$Skipped = 0 foreach($Row in $Table) { [string]$FolderName = $Row.FolderName [string]$Branch = $Row.Branch [string]$Shallow = $Row.Shallow [string]$URL = $Row.URL + $Step++ - if (test-path "$folder/$FolderName" -pathType container) { - "๐$FolderName exists, skipping..." + if (test-path "$FolderPath/$FolderName" -pathType container) { + "โณ Step $Step/$($NumEntries): skipping already existing ๐$($FolderName)..." + $Skipped++ continue } if ($Shallow -eq "yes") { - "๐ข Cloning to ๐$FolderName, $Branch branch, shallow..." - & git clone --branch "$Branch" --depth 1 --shallow-submodules --recurse-submodules "$URL" "$folder/$FolderName" + "โณ Step $Step/$($NumEntries): cloning shallow $Branch branch to ๐$($FolderName)..." + & git clone --branch "$Branch" --depth 1 --shallow-submodules --recurse-submodules "$URL" "$FolderPath/$FolderName" } else { - "๐ข Cloning to ๐$FolderName, $Branch branch, full history..." - & git clone --branch "$Branch" --recurse-submodules "$URL" "$folder/$FolderName" + "โณ Step $Step/$($NumEntries): cloning full $Branch branch to ๐$FolderName..." + & git clone --branch "$Branch" --recurse-submodules "$URL" "$FolderPath/$FolderName" } if ($lastExitCode -ne "0") { throw "'git clone $URL' failed" } - $Count++ + $Cloned++ } [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds - "โ๏ธ cloned $Count Git repositories into ๐$folder in $Elapsed sec" + "โ๏ธ $Cloned Git repositories cloned, $Skipped skipped in ๐$ParentFolderName in $Elapsed sec" exit 0 # success } catch { "โ ๏ธ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"