From e1feb432538a5fc461059b3b7ff8860f88faf301 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 28 Feb 2022 10:57:50 +0100 Subject: [PATCH] Update clean-repo.ps1 --- Scripts/clean-repo.ps1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Scripts/clean-repo.ps1 b/Scripts/clean-repo.ps1 index 8db0028c..3fc5bac2 100755 --- a/Scripts/clean-repo.ps1 +++ b/Scripts/clean-repo.ps1 @@ -1,14 +1,13 @@ <# .SYNOPSIS - Cleans a Git repository from untracked files (including submodules) + Cleans a Git repository from untracked files .DESCRIPTION - This PowerShell script cleans a Git repository from untracked files (including submodules). + This PowerShell script deletes all untracked files and folders in a Git repository (including submodules). + IMPORTANT NOTE: To be used with care! This cannot be undone! .PARAMETER RepoDir Specifies the path to the Git repository .EXAMPLE PS> ./clean-repo C:\MyRepo - 🧹 Cleaning from untracked files... - ✔️ cleaned Git repository 📂C:\MyRepo in 0 sec .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -20,20 +19,21 @@ param([string]$RepoDir = "$PWD") try { $StopWatch = [system.diagnostics.stopwatch]::startNew() - if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } - - $RepoDirName = (get-item "$RepoDir").Name - "🧹 Cleaning from untracked files..." + "⏳ Step 1/3: Checking requirements..." + if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access repository folder at: $RepoDir - maybe a typo or missing folder permissions?" } $Null = (git --version) if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } - + + "⏳ Step 2/3: Cleaning repository..." & git -C "$RepoDir" clean -xfd -f # force + recurse into dirs + don't use the standard ignore rules - if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' failed" } + if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' failed (exited with $lastExitCode)" } + "⏳ Step 3/3: Cleaning submodules..." & git -C "$RepoDir" submodule foreach --recursive git clean -xfd -f - if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' in submodules failed" } + if ($lastExitCode -ne "0") { throw "'git clean -xfd -f' in submodules failed (exited with $lastExitCode)" } + $RepoDirName = (get-item "$RepoDir").Name [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds "✔️ cleaned Git repository 📂$RepoDirName in $Elapsed sec" exit 0 # success