mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-10 18:44:50 +02:00
Updated list-repos.ps1 and switch-branch.ps1
This commit is contained in:
parent
fc487f5f3d
commit
37075acd8c
@ -8,9 +8,9 @@
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./list-repos.ps1 C:\MyRepos
|
PS> ./list-repos.ps1 C:\MyRepos
|
||||||
|
|
||||||
REPOSITORY LATEST TAG BRANCH REMOTE URL STATUS
|
REPOSITORY LATEST TAG BRANCH REMOTE URL STATUS
|
||||||
---------- ---------- ------ ---------- ------
|
---------- ---------- ------ ---------- ------
|
||||||
📂cmake v3.30.2 master https://github.com/Kitware/CMake ✅clean ↓0
|
📂cmake v3.30.2 master https://github.com/Kitware/CMake ↓0 ✅clean
|
||||||
...
|
...
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
@ -36,7 +36,7 @@ function ListRepos {
|
|||||||
$status = (git -C "$dir" status --short)
|
$status = (git -C "$dir" status --short)
|
||||||
if ("$status" -eq "") { $status = "✅clean" }
|
if ("$status" -eq "") { $status = "✅clean" }
|
||||||
elseif ("$status" -like " M *") { $status = "⚠️changed" }
|
elseif ("$status" -like " M *") { $status = "⚠️changed" }
|
||||||
New-Object PSObject -property @{'REPOSITORY'="📂$dirName";'LATEST TAG'="$latestTag";'BRANCH'="$branch";'REMOTE URL'="$remoteURL";'STATUS'="$status ↓$numCommits"}
|
New-Object PSObject -property @{'REPOSITORY'="📂$dirName";'LATEST TAG'="$latestTag";'BRANCH'="$branch";'REMOTE URL'="$remoteURL ↓$numCommits";'STATUS'="$status"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,9 +44,9 @@ try {
|
|||||||
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access parent directory at: $parentDir" }
|
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access parent directory at: $parentDir" }
|
||||||
|
|
||||||
$null = (git --version)
|
$null = (git --version)
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
|
|
||||||
ListRepos | Format-Table -property @{e='REPOSITORY';width=19},@{e='LATEST TAG';width=16},@{e='BRANCH';width=19},@{e='REMOTE URL';width=47},@{e='STATUS';width=12}
|
ListRepos | Format-Table -property @{e='REPOSITORY';width=19},@{e='LATEST TAG';width=16},@{e='BRANCH';width=19},@{e='REMOTE URL';width=50},@{e='STATUS';width=10}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
@ -31,33 +31,33 @@ try {
|
|||||||
|
|
||||||
Write-Host "⏳ (1/6) Searching for Git executable... " -noNewline
|
Write-Host "⏳ (1/6) Searching for Git executable... " -noNewline
|
||||||
& git --version
|
& git --version
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
|
|
||||||
Write-Host "⏳ (2/6) Checking local repository... $pathToRepo"
|
Write-Host "⏳ (2/6) Checking local repository... $pathToRepo"
|
||||||
if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access repo folder: $pathToRepo" }
|
if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access repo folder: $pathToRepo" }
|
||||||
$result = (git -C "$pathToRepo" status)
|
$result = (git -C "$pathToRepo" status)
|
||||||
if ($lastExitCode -ne "0") { throw "'git status' in $pathToRepo failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git status' in $pathToRepo failed with exit code $lastExitCode" }
|
||||||
if ("$result" -notmatch "nothing to commit, working tree clean") { throw "Git repository is NOT clean: $result" }
|
if ("$result" -notmatch "nothing to commit, working tree clean") { throw "Git repository is NOT clean: $result" }
|
||||||
$repoDirName = (Get-Item "$pathToRepo").Name
|
$repoDirName = (Get-Item "$pathToRepo").Name
|
||||||
|
|
||||||
Write-Host "⏳ (3/6) Fetching remote updates... " -noNewline
|
Write-Host "⏳ (3/6) Fetching remote updates... " -noNewline
|
||||||
& git -C "$pathToRepo" remote get-url origin
|
& git -C "$pathToRepo" remote get-url origin
|
||||||
if ($lastExitCode -ne "0") { throw "'git remote get-url origin' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git remote get-url origin' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
& git -C "$pathToRepo" fetch --all --prune --prune-tags --force
|
& git -C "$pathToRepo" fetch --all --prune --prune-tags --force
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git fetch' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
"⏳ (4/6) Switching to branch '$branchName'..."
|
"⏳ (4/6) Switching to branch '$branchName'..."
|
||||||
& git -C "$pathToRepo" checkout --recurse-submodules "$branchName"
|
& git -C "$pathToRepo" checkout --recurse-submodules "$branchName"
|
||||||
if ($lastExitCode -ne "0") { throw "'git checkout $branchName' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git checkout $branchName' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
"⏳ (5/6) Pulling remote updates..."
|
"⏳ (5/6) Pulling remote updates..."
|
||||||
& git -C "$pathToRepo" pull --recurse-submodules
|
& git -C "$pathToRepo" pull --recurse-submodules
|
||||||
if ($lastExitCode -ne "0") { throw "'git pull' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git pull' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
"⏳ (6/6) Updating submodules..."
|
"⏳ (6/6) Updating submodules..."
|
||||||
& git -C "$pathToRepo" submodule update --init --recursive
|
& git -C "$pathToRepo" submodule update --init --recursive
|
||||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git submodule update' failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"✅ Switched 📂$repoDirName repo to '$branchName' branch in $($elapsed)s."
|
"✅ Switched 📂$repoDirName repo to '$branchName' branch in $($elapsed)s."
|
||||||
|
Loading…
Reference in New Issue
Block a user