mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-28 07:38:38 +01:00
Update fetch-repo.ps1 and pull-repo.ps1
This commit is contained in:
parent
03b6623128
commit
3ac68d5826
@ -1,39 +1,38 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Fetches updates for a Git repository
|
Fetches Git repository updates
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script fetches updates for a local Git repository (including submodules).
|
This PowerShell script fetches updates for a local Git repository (including submodules).
|
||||||
.PARAMETER RepoDir
|
.PARAMETER RepoDir
|
||||||
Specifies the path to the Git repository.
|
Specifies the path to the Git repository.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./fetch-repo
|
PS> ./fetch-repo
|
||||||
🢃 Fetching updates...
|
|
||||||
✔️ fetched updates for Git repository 📂PowerShell in 14 sec
|
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz / License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$RepoDir = "$PWD")
|
param([string]$RepoDir = "$PWD")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
"🢃 Fetching updates..."
|
|
||||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
"⏳ Step 1/2: Checking requirements... "
|
||||||
|
& 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" }
|
||||||
|
|
||||||
|
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
|
||||||
|
|
||||||
|
"⏳ Step 2/2: Fetching updates... "
|
||||||
& git -C "$RepoDir" fetch --all --recurse-submodules --prune --prune-tags --force
|
& git -C "$RepoDir" fetch --all --recurse-submodules --prune --prune-tags --force
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' in $RepoDir failed" }
|
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
$RepoDirName = (get-item "$RepoDir").Name
|
$RepoDirName = (get-item "$RepoDir").Name
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
"✔️ fetched updates for Git repository 📂$RepoDirName in $Elapsed sec"
|
"✔️ fetched updates for Git repository 📂$RepoDirName in $Elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Pulls repository updates
|
Pulls Git repository updates
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script pulls updates for the given local Git repository (including submodules).
|
This PowerShell script pulls updates for a local Git repository (including submodules).
|
||||||
.PARAMETER RepoDir
|
.PARAMETER RepoDir
|
||||||
Specifies the path to the Git repository
|
Specifies the path to the Git repository
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./pull-repo C:\MyRepo
|
PS> ./pull-repo
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -29,11 +29,11 @@ try {
|
|||||||
|
|
||||||
"⏳ Step 2/3: Pulling updates... "
|
"⏳ Step 2/3: Pulling updates... "
|
||||||
& git -C "$RepoDir" pull --recurse-submodules --jobs=4
|
& git -C "$RepoDir" pull --recurse-submodules --jobs=4
|
||||||
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
|
if ($lastExitCode -ne "0") { throw "'git pull' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
"⏳ Step 3/3: Updating submodules... "
|
"⏳ Step 3/3: Updating submodules... "
|
||||||
& git -C "$RepoDir" submodule update --init --recursive
|
& git -C "$RepoDir" submodule update --init --recursive
|
||||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
$RepoDirName = (Get-Item "$RepoDir").Name
|
$RepoDirName = (Get-Item "$RepoDir").Name
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
|
Loading…
Reference in New Issue
Block a user