mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-14 00:46:59 +02:00
Improve fetch-repo.ps1
This commit is contained in:
parent
79497e5e00
commit
28e29aeac8
@ -2,9 +2,13 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Fetches updates for a local Git repository (including submodules)
|
Fetches updates for a local Git repository (including submodules)
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
fetch-repo.ps1 [<repo-dir>]
|
fetch-repo.ps1 [<RepoDir>]
|
||||||
|
.PARAMETER RepoDir
|
||||||
|
Specifies the path to the Git repository.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./fetch-repo
|
PS> ./fetch-repo
|
||||||
|
🢃 Fetching updates for Git repository 📂PowerShell ...
|
||||||
|
✔️ fetched updates for 📂PowerShell"
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz · License: CC0
|
Author: Markus Fleschutz · License: CC0
|
||||||
.LINK
|
.LINK
|
||||||
@ -14,18 +18,20 @@
|
|||||||
param([string]$RepoDir = "$PWD")
|
param([string]$RepoDir = "$PWD")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
"🢃 Fetching updates..."
|
||||||
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||||
|
|
||||||
$Null = (git --version)
|
$Null = (git --version)
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
|
|
||||||
|
& git -C "$RepoDir" fetch --all --recurse-submodules --prune --prune-tags --jobs=4
|
||||||
|
if ($lastExitCode -ne "0") { throw "'git fetch' in $RepoDir failed" }
|
||||||
|
|
||||||
$RepoDirName = (get-item "$RepoDir").Name
|
$RepoDirName = (get-item "$RepoDir").Name
|
||||||
"🢃 Fetching updates for Git repository 📂$RepoDirName ..."
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
|
"✔️ fetched updates for Git repository 📂$RepoDirName in $Elapsed sec"
|
||||||
& git -C "$RepoDir" fetch --all --recurse-submodules --jobs=4
|
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
|
||||||
|
|
||||||
"✔️ fetched updates for 📂$RepoDirName"
|
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user