Added switch-branch.ps1

This commit is contained in:
Markus Fleschutz
2021-02-13 10:26:14 +01:00
parent 0d969091d0
commit 89c6ff871b
6 changed files with 57 additions and 15 deletions

View File

@ -6,9 +6,15 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
$PathToRepo = "$PSScriptRoot/.."
try {
& git --version
} catch {
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
try {
$PathToRepo = "$PSScriptRoot/.."
$Table = import-csv "$PathToRepo/Data/repos.csv"
foreach($Row in $Table) {
@ -16,11 +22,11 @@ try {
$Directory = $Row.Directory
write-output ""
if (Test-Path($Directory)) {
write-output "Skipping $Directory (already existent) ..."
write-output "Skipping existing $Directory ..."
continue
}
write-output "Cloning from $URL..."
git clone --recurse-submodules $URL
& git clone --recurse-submodules $URL
}
exit 0
} catch {

View File

@ -9,9 +9,9 @@
param($FullName = "", $EmailAddress = "", $FavoriteEditor = "")
try {
git --version
& git --version
} catch {
write-error "No Git installation found - make sure Git is installed"
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
@ -25,15 +25,15 @@ try {
if ($FavoriteEditor -eq "") {
$FavoriteEditor = read-host "Enter your favorite text editor (emacs,nano,vi,vim,...)"
}
git config --global user.name $FullName
git config --global user.email $EmailAddress
git config --global core.editor $FavoriteEditor
git config --global http.sslVerify false
git config --global core.autocrlf false
git config --global core.symlinks true
git config --global init.defaultBranch main
& git config --global user.name $FullName
& git config --global user.email $EmailAddress
& git config --global core.editor $FavoriteEditor
& git config --global http.sslVerify false
& git config --global core.autocrlf false
& git config --global core.symlinks true
& git config --global init.defaultBranch main
write-host -foregroundColor green "Done - your Git user configuration is now:"
git config --list
& git config --list
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

27
Scripts/switch-branch.ps1 Executable file
View File

@ -0,0 +1,27 @@
#!/bin/powershell
<#
.SYNTAX ./switch-branch.ps1 [<branch>]
.DESCRIPTION switches to the given Git branch
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Branch = "")
try {
& git --version
} catch {
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
try {
if ($Branch -eq "") {
$Branch = read-host "Enter branch name to switch to"
}
& git switch --recurse-submodules $Branch
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -6,7 +6,14 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
param([string]$Directory = "")
param($Directory = "")
try {
& git --version
} catch {
write-error "Can't execute 'git' - make sure Git is installed and available"
exit 1
}
try {
if ($Directory -eq "") {
@ -19,7 +26,7 @@ try {
write-host ""
write-host -nonewline "Updating $Filename ..."
set-location $Filename
git pull
& git pull --recurse-submodules
set-location ..
}
}