Add remove-tag.ps1

This commit is contained in:
Markus Fleschutz 2021-09-06 13:48:26 +02:00
parent 651394001c
commit 3354e959ff
3 changed files with 47 additions and 0 deletions

View File

@ -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

Can't render this file because it has a wrong number of fields in line 83.

View File

@ -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) |

45
Scripts/remove-tag.ps1 Executable file
View File

@ -0,0 +1,45 @@
<#
.SYNOPSIS
remove-tag.ps1 [<TagName>] [<Mode>] [<RepoDir>]
.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
}