Improve create-branch.ps1

This commit is contained in:
Markus Fleschutz 2021-06-18 11:01:51 +02:00
parent 04afaf32c6
commit ca7014b2c1

View File

@ -9,18 +9,16 @@ param($NewBranchName = "", $RepoDir = "$PWD")
if ($NewBranchName -eq "") { $NewBranchName = read-host "Enter new branch name" }
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir"
$Null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
$Result = (git status)
if ($lastExitCode -ne "0") { throw "'git status' failed in $RepoDir" }
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Repository is NOT clean: $Result" }
$RepoDirName = (get-item "$RepoDir").Name
" Fetching updates for Git repository 📂$RepoDirName ..."
"🢃 Fetching updates for Git repository 📂$RepoDirName ..."
& git fetch --all --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
@ -34,7 +32,8 @@ try {
& git submodule update --init --recursive
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
"✔️ created new 🌵$NewBranchName branch in Git repository 📂$RepoDirName"
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ created new branch '$NewBranchName' in Git repository 📂$RepoDirName in $Elapsed sec"
exit 0
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"