Skip to content

Commit

Permalink
Merge pull request #8 from thrawn01/thrawn/develop
Browse files Browse the repository at this point in the history
Added --prefix option to clip-remote
  • Loading branch information
thrawn01 committed Oct 9, 2021
2 parents a3fe90b + 390b78a commit ffc52f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 2 additions & 1 deletion clip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

type TrackedBranch struct {
Name string
Remote string
Merge string
}
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions cmd/clip-remote/clip-remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/thrawn01/args"
"github.com/thrawn01/clip"
Expand All @@ -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")

Expand Down Expand Up @@ -48,6 +52,7 @@ func main() {
if branch.Name == "HEAD" {
continue
}

// Does this branch exist locally?
if clip.ExistsLocally(branch, refs) {
continue
Expand All @@ -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'"
Expand Down

0 comments on commit ffc52f4

Please sign in to comment.