Improve output of clean-repo.ps1 and clean-repos.ps1

This commit is contained in:
Markus Fleschutz 2021-05-07 14:17:45 +02:00
parent 96ae539454
commit 4f74a5f1ce
2 changed files with 9 additions and 13 deletions

View File

@ -8,22 +8,21 @@
param($RepoDir = "$PWD")
try {
$RepoDir = resolve-path "$RepoDir"
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir"
"⏳ Cleaning Git repository 📂$RepoDir from untracked files..."
$RepoDirName = (get-item "$RepoDir").Name
"🧹 Cleaning Git repository 📂$RepoDirName from untracked files..."
$Null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
& git clean -fdx # force + recurse into dirs + don't use the standard ignore rules
& git -C "$RepoDir" clean -fdx # force + recurse into dirs + don't use the standard ignore rules
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" }
& git submodule foreach --recursive git clean -fdx
& git -C "$RepoDir" submodule foreach --recursive git clean -fdx
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" }
"✔️ cleaned Git repository 📂$RepoDir"
"✔️ cleaned Git repository 📂$RepoDirName"
exit 0
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -11,23 +11,20 @@ try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
set-location $ParentDir
$Null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
[int]$Count = 0
get-childItem "$ParentDir" -attributes Directory | foreach-object {
"Cleaning Git repository 📂$($_.Name) from untracked files ..."
set-location $_.FullName
"🧹 Cleaning Git repository 📂$($_.Name) from untracked files ..."
& git clean -fdx # force + recurse into dirs + don't use the standard ignore rules
& git -C "$_.FullName" clean -fdx # force + recurse into dirs + don't use the standard ignore rules
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" }
& git submodule foreach --recursive git clean -fdx
& git -C "$._FullName" submodule foreach --recursive git clean -fdx
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" }
set-location ..
$Count++
}