From 3354e959ffe648d8384ce3c634748dc794f8e82c Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 6 Sep 2021 13:48:26 +0200 Subject: [PATCH] Add remove-tag.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/remove-tag.ps1 | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100755 Scripts/remove-tag.ps1 diff --git a/Data/scripts.csv b/Data/scripts.csv index 77b484b2..988abead 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -184,6 +184,7 @@ reboot.ps1, reboots the local computer (needs admin rights) reboot-fritzbox.ps1, reboots the FRITZ!box device remove-empty-dirs.ps1, removes empty subfolders within the given directory tree remove-print-jobs.ps1, removes all jobs from all printers +remove-tag.ps1, removes a tag in a Git repository restart-network-adapters.ps1, restarts all local network adapters search-filename.ps1, searches the directory tree for filenames by given pattern search-files.ps1, searches the given pattern in the given files diff --git a/README.md b/README.md index 2a053e16..88af42d2 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,7 @@ Mega Collection of PowerShell Scripts | [new-tag.ps1](Scripts/new-tag.ps1) | Creates a new tag in a Git repository | [Help](Docs/new-tag.ps1.md) | | [pull-repo.ps1](Scripts/pull-repo.ps1) | Pulls updates for a Git repository (including submodules) | [Help](Docs/pull-repo.ps1.md) | | [pull-repos.ps1](Scripts/pull-repos.ps1) | Pulls updates for all Git repositories under a directory (including submodules) | [Help](Docs/pull-repos.ps1.md)| +| [remove-tag.ps1](Scripts/remove-tag.ps1) | Removes a tag in a Git repository | [Help](Docs/remove-tag.ps1.md) | | [switch-branch.ps1](Scripts/switch-branch.ps1) | Switches the branch in a Git repository (including submodules) | [Help](Docs/switch-branch.ps1.md) | | [sync-repo.ps1](Scripts/sync-repo.ps1) | Synchronizes a Git repository by push & pull (including submodules) | [Help](Docs/sync-repo.ps1.md) | diff --git a/Scripts/remove-tag.ps1 b/Scripts/remove-tag.ps1 new file mode 100755 index 00000000..0d37b950 --- /dev/null +++ b/Scripts/remove-tag.ps1 @@ -0,0 +1,45 @@ +<# +.SYNOPSIS + remove-tag.ps1 [] [] [] +.DESCRIPTION + Removes a Git tag (locally, remote, or both) +.EXAMPLE + PS> .\remove-tag.ps1 v1.7 locally +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz · License: CC0 +#> + +param([string]$TagName = "", [string]$Mode = "", [string]$RepoDir = "$PWD") + +try { + if ($TagName -eq "") { $TagName = read-host "Enter new tag name" } + if ($Mode -eq "") { $Mode = read-host "Remove the tag locally, remote, or both" } + + $StopWatch = [system.diagnostics.stopwatch]::startNew() + + if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } + + $Null = (git --version) + if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } + + if (($Mode -eq "locally") -or ($Mode -eq "both")) { + "Removing local tag..." + & git -C "$RepoDir" tag --delete $TagName + if ($lastExitCode -ne "0") { throw "'git tag --delete' failed" } + } + + if (($Mode -eq "remote") -or ($Mode -eq "both")) { + "Removing remote tag..." + & git -C "$RepoDir" push origin :refs/tags/$TagName + if ($lastExitCode -ne "0") { throw "'git push origin' failed" } + } + + [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds + "✔️ removed tag '$TagName' in $Elapsed sec" + exit 0 +} catch { + write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}