Improved the scripts

This commit is contained in:
Markus Fleschutz 2021-02-28 18:49:53 +01:00
parent 032113200c
commit ab6a0ce13f
5 changed files with 38 additions and 32 deletions

View File

@ -1,7 +1,7 @@
#!/bin/powershell
<#
.SYNTAX ./clean-branch.ps1 [<repo-dir>]
.DESCRIPTION cleans the current/given Git branch including submodules from generated files (e.g. for a fresh build)
.DESCRIPTION cleans the current Git branch including submodules from generated files (e.g. for a fresh build)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
@ -16,6 +16,7 @@ try {
}
try {
write-progress "Cleaning current branch in repository $RepoDir..."
set-location $RepoDir
& git clean -fdx # force + recurse into dirs + don't use the standard ignore rules
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" }
@ -26,6 +27,7 @@ try {
& git status
if ($lastExitCode -ne "0") { throw "'git status' failed" }
write-host -foregroundColor green "OK - cleaned current branch in repository $RepoDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,11 +1,13 @@
#!/bin/powershell
<#
.SYNTAX ./clone-repos.ps1
.DESCRIPTION clones well-known Git repositories into the current directory.
.SYNTAX ./clone-repos.ps1 [<target-dir>]
.DESCRIPTION clones well-known Git repositories into the current/given directory.
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($TargetDir = "$PWD")
try {
& git --version
} catch {
@ -17,6 +19,7 @@ try {
$PathToRepo = "$PSScriptRoot/.."
$Table = import-csv "$PathToRepo/Data/repos.csv"
set-location $TargetDir
foreach($Row in $Table) {
$URL = $Row.URL
$Directory = $Row.Directory

View File

@ -1,12 +1,12 @@
#!/bin/powershell
<#
.SYNTAX ./fetch-repos.ps1 [<repo-dir>]
.SYNTAX ./fetch-repos.ps1 [<parent-dir>]
.DESCRIPTION fetches all Git repositories under the current/given directory (including submodules)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($RepoDir = "$PWD")
param($ParentDir = "$PWD")
try {
$null = $(git --version)
@ -16,12 +16,18 @@ try {
}
try {
write-progress "Fetching repository $RepoDir ..."
set-location $RepoDir
& git fetch --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git fetch --recurse-submodules' failed" }
write-progress "Fetching repositories under $ParentDir ..."
set-location $ParentDir
get-childItem $ParentDir -attributes Directory | foreach-object {
set-location $_.FullName
write-host -foregroundColor green "OK - fetched repository $RepoDir"
& git fetch --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git fetch --recurse-submodules' failed" }
set-location ..
}
write-host -foregroundColor green "OK - fetched repositories under $ParentDir"
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,12 +1,12 @@
#!/bin/powershell
<#
.SYNTAX ./switch-branch.ps1 [<branch>]
.DESCRIPTION switches the current Git repository to the given branch (including submodules)
.SYNTAX ./switch-branch.ps1 [<branch>] [<repo-dir>]
.DESCRIPTION switches the current/given Git repository to the given branch (including submodules)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Branch = "")
param($Branch = "", $RepoDir = "$PWD")
if ($Branch -eq "") {
$Branch = read-host "Enter branch name to switch to"
@ -20,6 +20,8 @@ try {
}
try {
set-location $RepoDir
& git switch --recurse-submodules $Branch
if ($lastExitCode -ne "0") { throw "'git switch --recurse-submodules $Branch' failed" }
@ -29,9 +31,6 @@ try {
& git pull --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
& git status
if ($lastExitCode -ne "0") { throw "'git status' failed" }
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,16 +1,12 @@
#!/bin/powershell
<#
.SYNTAX ./update-repos.ps1 [<directory>]
.SYNTAX ./update-repos.ps1 [<parent-dir>]
.DESCRIPTION updates all Git repositories under the current/given directory (including submodules)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Directory = "")
if ($Directory -eq "") {
$Directory = "$PWD"
}
param($ParentDir = "$PWD")
try {
& git --version
@ -20,16 +16,16 @@ try {
}
try {
$Files = get-childItem -path $Directory
foreach ($File in $Files) {
if ($File.Mode -like "d*") {
$Filename = $File.Name
write-host ""
write-host -nonewline "Updating $Filename ..."
set-location $Filename
& git pull --recurse-submodules
set-location ..
}
set-location $ParentDir
get-childItem $ParentDir -attributes Directory | foreach-object {
set-location $_.FullName
write-host ""
write-host -nonewline "Updating $($_.FullName)..."
& git pull --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git pull --recurse-submodules' failed" }
set-location ..
}
exit 0
} catch {