mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-08 17:14:28 +01:00
Add sync-repo.ps1
This commit is contained in:
parent
41ccb7867b
commit
fbad5259f7
@ -155,6 +155,7 @@ speak-text.ps1, speaks the given text by text-to-speech (TTS)
|
||||
speak-time.ps1, speaks the current time by text-to-speech (TTS)
|
||||
switch-branch.ps1, switches the branch in the current/given Git repository (including submodules)
|
||||
switch-shelly1.ps1, switches a Shelly1 device in the local network
|
||||
sync-repo.ps1, synchronizes a Git repository (pull&push, including submodules)
|
||||
take-screenshot.ps1, takes a single screenshot
|
||||
take-screenshots.ps1, takes multiple screenshots
|
||||
translate-file.ps1, translates the given text file into another language
|
||||
|
Can't render this file because it has a wrong number of fields in line 158.
|
@ -138,6 +138,7 @@ Mega Collection of PowerShell Scripts
|
||||
* [pull-repo.ps1](Scripts/pull-repo.ps1) - pulls updates for the current/given Git repository (including submodules)
|
||||
* [pull-repos.ps1](Scripts/pull-repos.ps1) - pulls updates for all Git repositories under the current/given directory (including submodules)
|
||||
* [switch-branch.ps1](Scripts/switch-branch.ps1) - switches the branch in the current/given Git repository (including submodules)
|
||||
* [sync-repo.ps1](Scripts/sync-repo.ps1) - synchronizes a Git repository (pull&push, including submodules)
|
||||
|
||||
🔎 Scripts for PowerShell
|
||||
------------------------
|
||||
|
31
Scripts/sync-repo.ps1
Normal file
31
Scripts/sync-repo.ps1
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/pwsh
|
||||
<#
|
||||
.SYNTAX sync-repo.ps1 [<repo-dir>]
|
||||
.DESCRIPTION synchronizes a Git repository (pull&push, including submodules)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($RepoDir = "$PWD")
|
||||
|
||||
try {
|
||||
"⏳ Synchronizing Git repository $($RepoDir)..."
|
||||
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
& git pull --all --recurse-submodules --jobs=4
|
||||
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
|
||||
|
||||
& git push
|
||||
if ($lastExitCode -ne "0") { throw "'git push' failed" }
|
||||
|
||||
"✔️ Git repository $RepoDir synchronized"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user