From 2a2320603ca7e1f5375fcf46ce5f96298a2d1c7d Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sat, 20 Mar 2021 14:36:45 +0100 Subject: [PATCH] Improve fetch-repos.ps1 and pull-repos.ps1 --- Scripts/fetch-repos.ps1 | 17 ++++++++--------- Scripts/pull-repos.ps1 | 19 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Scripts/fetch-repos.ps1 b/Scripts/fetch-repos.ps1 index 2206c221..f10f1ea7 100755 --- a/Scripts/fetch-repos.ps1 +++ b/Scripts/fetch-repos.ps1 @@ -9,28 +9,27 @@ param($ParentDir = "$PWD") try { - $null = $(git --version) -} catch { - write-error "ERROR: can't execute 'git' - make sure Git is installed and available" - exit 1 -} - -try { - write-progress "Fetching updates for Git repositories under $ParentDir ..." + "Fetching updates for Git repositories under $ParentDir ..." if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" } set-location $ParentDir + & git --version + if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } + + [int]$Count = 0 get-childItem $ParentDir -attributes Directory | foreach-object { + "Fetching Git repository $($_.FullName) ..." set-location $_.FullName & git fetch --all --recurse-submodules if ($lastExitCode -ne "0") { throw "'git fetch --all --recurse-submodules' failed" } set-location .. + $Count++ } - write-host -foregroundColor green "OK - fetched updates for Git repositories under $ParentDir" + write-host -foregroundColor green "OK - fetched updates for $Count Git repositories under $ParentDir" exit 0 } catch { write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/pull-repos.ps1 b/Scripts/pull-repos.ps1 index f668d260..c9e8949f 100755 --- a/Scripts/pull-repos.ps1 +++ b/Scripts/pull-repos.ps1 @@ -9,28 +9,27 @@ param($ParentDir = "$PWD") try { - & git --version -} catch { - write-error "ERROR: can't execute 'git' - make sure Git is installed and available" - exit 1 -} - -try { - write-progress "Pulling updates for Git repositories under $ParentDir ..." + "Pulling updates for Git repositories under $ParentDir ..." if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" } set-location "$ParentDir" + & git --version + if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } + + [int]$Count = 0 get-childItem $ParentDir -attributes Directory | foreach-object { + "Pulling Git repository $($_.FullName)..." + set-location $_.FullName - write-host "" - write-host -nonewline "Pulling $($_.FullName)..." & git pull --recurse-submodules if ($lastExitCode -ne "0") { throw "'git pull --recurse-submodules' failed" } set-location .. + $Count++ } + write-host -foregroundColor green "OK - pulled updates for $Count Git repositories under $ParentDir" exit 0 } catch { write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"