mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-16 17:51:28 +01:00
Improve create-branch.ps1
This commit is contained in:
parent
04afaf32c6
commit
ca7014b2c1
@ -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])"
|
||||
|
Loading…
Reference in New Issue
Block a user