mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-22 20:51:17 +01:00
Update clean-repo.ps1 and clean-repos.ps1
This commit is contained in:
parent
28546f9a46
commit
d5e5f5cecf
@ -40,7 +40,7 @@ try {
|
||||
if ($lastExitCode -ne "0") { throw "'git clean' in the submodules failed with exit code $lastExitCode" }
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cleaned 📂$RepoDirName repository in $Elapsed sec"
|
||||
"✔️ cleaned Git repository 📂$RepoDirName in $Elapsed sec"
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -18,31 +18,31 @@ param([string]$ParentDir = "$PWD")
|
||||
try {
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }
|
||||
Write-Host "⏳ (1) Searching for Git executable... " -noNewline
|
||||
& git --version
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
|
||||
$Null = (git --version)
|
||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||
$ParentDirName = (Get-Item "$ParentDir").Name
|
||||
Write-Host "⏳ (2) Checking parent folder 📂$ParentDirName... " -noNewline
|
||||
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" }
|
||||
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
||||
$NumFolders = $Folders.Count
|
||||
Write-Host "$NumFolders subfolders found"
|
||||
|
||||
$Folders = (get-childItem "$ParentDir" -attributes Directory)
|
||||
$FolderCount = $Folders.Count
|
||||
$ParentDirName = (get-item "$ParentDir").Name
|
||||
"Found $FolderCount subfolders in 📂$ParentDirName, cleaning them from untracked files..."
|
||||
|
||||
[int]$Step = 1
|
||||
[int]$Step = 2
|
||||
foreach ($Folder in $Folders) {
|
||||
$FolderName = (get-item "$Folder").Name
|
||||
"⏳ Step $Step/$($FolderCount): Cleaning 📂$FolderName..."
|
||||
$FolderName = (Get-Item "$Folder").Name
|
||||
$Step++
|
||||
"⏳ ($Step/$($NumFolders + 2)) Cleaning 📂$FolderName..."
|
||||
|
||||
& git -C "$Folder" clean -xfd -f # force + recurse into dirs + don't use the standard ignore rules
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' failed with exit code $lastExitCode" }
|
||||
|
||||
& git -C "$Folder" submodule foreach --recursive git clean -xfd -f
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' in submodules failed with exit code $lastExitCode" }
|
||||
|
||||
$Step++
|
||||
}
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cleaned $FolderCount Git repositories at 📂$ParentDirName in $Elapsed sec"
|
||||
"✔️ cleaned $NumFolders Git repositories at 📂$ParentDirName in $Elapsed sec."
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user