diff --git a/Makefile b/Makefile index 174d724..2333080 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: all release darwin .DEFAULT_GOAL := all -VERSION=v0.2.1 +VERSION=v0.2.2 CWD=$(shell pwd) GIT_EXEC=$(shell git --exec-path) diff --git a/clip.go b/clip.go index a6bed98..f191670 100644 --- a/clip.go +++ b/clip.go @@ -12,6 +12,7 @@ import ( ) type TrackedBranch struct { + Name string Remote string Merge string } @@ -79,7 +80,7 @@ func ParseTrackedBranches(result TrackedBranchMap, input string) error { if tracked, ok := result[branch[1]]; ok { tracked.Remote = branch[2] } else { - result[branch[1]] = &TrackedBranch{Remote: branch[2]} + result[branch[1]] = &TrackedBranch{Name: branch[1], Remote: branch[2]} } } merge := regexMerge.FindStringSubmatch(line) diff --git a/cmd/clip-remote/clip-remote.go b/cmd/clip-remote/clip-remote.go index e5aa48e..9df5174 100644 --- a/cmd/clip-remote/clip-remote.go +++ b/cmd/clip-remote/clip-remote.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/exec" + "strings" "github.com/thrawn01/args" "github.com/thrawn01/clip" @@ -17,6 +18,9 @@ func main() { args.Desc("Clips remote branches that no longer are used locally")) parser.AddOption("--force").Alias("-f").IsTrue(). Help("Don't ask before deleting remote branches") + parser.AddOption("prefix").Default("").Alias("-p"). + Help("Attempt to prune only branches with this prefix." + + " IE: '-p thrawn' will prune 'thrawn/dev' and 'thrawn/clip' branches") parser.AddArgument("remote").Default("origin"). Help("The name of the remote to clip branches from") @@ -48,6 +52,7 @@ func main() { if branch.Name == "HEAD" { continue } + // Does this branch exist locally? if clip.ExistsLocally(branch, refs) { continue @@ -62,6 +67,12 @@ func main() { continue } + if prefix := opts.String("prefix"); prefix != "" { + if !strings.HasPrefix(branch.Name, prefix) { + continue + } + } + if !opts.Bool("force") { // Ask if we should delete this remote branch msg := "Delete Remote Branch '%s/%s'"