From c927d7263cc8e95a6dcf2ab2a76ba6eb262155a2 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 27 Apr 2021 15:26:00 +0200 Subject: [PATCH] Improve sync-repo.ps1 --- Data/scripts.csv | 2 +- README.md | 2 +- Scripts/sync-repo.ps1 | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Data/scripts.csv b/Data/scripts.csv index b147d6d3..2411e2b1 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -171,7 +171,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) +sync-repo.ps1, synchronizes a Git repository by push & pull (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 diff --git a/README.md b/README.md index ddb4a4d9..7f64a72c 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,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) +* [sync-repo.ps1](Scripts/sync-repo.ps1) - synchronizes a Git repository by push & pull (including submodules) 🔎 Scripts for PowerShell ------------------------ diff --git a/Scripts/sync-repo.ps1 b/Scripts/sync-repo.ps1 index 5c28cf5e..49796d21 100644 --- a/Scripts/sync-repo.ps1 +++ b/Scripts/sync-repo.ps1 @@ -1,6 +1,6 @@ <# .SYNTAX sync-repo.ps1 [] -.DESCRIPTION synchronizes a Git repository by pull & push (including submodules) +.DESCRIPTION synchronizes a Git repository by push & pull (including submodules) .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz / License: CC0 #> @@ -8,21 +8,22 @@ param($RepoDir = "$PWD") try { - "⏳ Synchronizing Git repository 📂$RepoDir ..." - if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } set-location "$RepoDir" + $RepoDirName = (Get-Item "$RepoDir").Name + + "⏳ Synchronizing Git repository 📂$RepoDirName ..." $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" } - "✔️ synchronized Git repository 📂$RepoDir" + & git pull --all --recurse-submodules --jobs=4 + if ($lastExitCode -ne "0") { throw "'git pull' failed" } + + "✔️ synchronized Git repository 📂$RepoDirName" exit 0 } catch { write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"