mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-02 10:59:14 +01:00
Add clean-repos.ps1
This commit is contained in:
parent
48bc38f2e6
commit
d2e582e05a
@ -36,6 +36,7 @@ check-windows-system-files.ps1, checks the validity of the Windows system files
|
||||
check-xml-file.ps1, checks the given XML file for validity
|
||||
cherry-picker.ps1, cherry-picks a Git commit into multiple branches
|
||||
clean-repo.ps1, cleans the current/given Git repository from untracked files (including submodules)
|
||||
clean-repos.ps1, cleans all Git repositories under the current/given directory from untracked files (including submodules)
|
||||
clear-recycle-bin.ps1, removes the content of the recycle bin folder (can not be undo!)
|
||||
clone-repos.ps1, clones well-known Git repositories
|
||||
close-calculator.ps1, closes the calculator program gracefully
|
||||
|
|
@ -143,6 +143,7 @@ Mega Collection of PowerShell Scripts
|
||||
* [build-repos.ps1](Scripts/build-repos.ps1) - builds all Git repositories under the current/given directory
|
||||
* [cherry-picker.ps1](Scripts/cherry-picker.ps1) - cherry-picks a Git commit into multiple branches
|
||||
* [clean-repo.ps1](Scripts/clean-repo.ps1) - cleans the current/given Git repository from untracked files (including submodules)
|
||||
* [clean-repos.ps1](Scripts/clean-repos.ps1) - cleans all Git repositories under the current/given directory from untracked files (including submodules)
|
||||
* [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories
|
||||
* [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git user configuration
|
||||
* [create-branch.ps1](Scripts/create-branch.ps1) - creates a new branch in the current/given Git repository
|
||||
|
40
Scripts/clean-repos.ps1
Executable file
40
Scripts/clean-repos.ps1
Executable file
@ -0,0 +1,40 @@
|
||||
<#
|
||||
.SYNTAX clean-repos.ps1 [<parent-dir>]
|
||||
.DESCRIPTION cleans all Git repositories under the current/given directory from untracked files (including submodules)
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param($ParentDir = "$PWD")
|
||||
|
||||
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
|
||||
|
||||
& git 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
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" }
|
||||
|
||||
set-location ..
|
||||
$Count++
|
||||
}
|
||||
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
write-host -foregroundColor green "✔️ cleaned $Count Git repositories at $ParentDir in $Elapsed sec."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user