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

View File

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

View File

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

View File

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

View File

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