Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/clienter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Clienter interface {
GetRemoteNames(ctx context.Context, dirs []string) ([]string, error)
GetRepos(ctx context.Context, name string) ([]*github.Repository, error)
GetTagNames(ctx context.Context, dirs []string) ([]string, error)
ListTags(ctx context.Context, repoDirs []string, args ...string) error
ListTags(ctx context.Context, repoDirs []string, ignoreEmpty bool, args ...string) error
LogRepos(ctx context.Context, repoDirs []string, ignoreEmpty bool, args ...string) error
MergeRepos(ctx context.Context, repoDirs []string, args ...string) error
PullRepos(ctx context.Context, repoDirs []string, args ...string) error
Expand Down
9 changes: 7 additions & 2 deletions client/repos/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/gosuri/uiprogress"
)

func (r *Repos) ListTags(ctx context.Context, dirs []string, args ...string) error {
func (r *Repos) ListTags(ctx context.Context, dirs []string, ignoreEmpty bool, args ...string) error {
args = append([]string{"tag"}, args...)

verbose := ctxhelper.Verbose(ctx)
Expand All @@ -36,9 +36,14 @@ func (r *Repos) ListTags(ctx context.Context, dirs []string, args ...string) err
cmd.Stderr = errout
cmd.Dir = dir

err := cmd.Run()

if ignoreEmpty && out.Len() == 0 && err == nil {
continue
}

r.scrb.BeginDescribe(dir)

err := cmd.Run()
if err != nil {
r.scrb.Error(err)
r.scrb.PrintLines(errout)
Expand Down
2 changes: 1 addition & 1 deletion client/testclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *TestClient) Branches(ctx context.Context, repoDirs []string, args ...st
return c.Errors["Branches"]
}

func (c *TestClient) ListTags(ctx context.Context, repoDirs []string, args ...string) error {
func (c *TestClient) ListTags(ctx context.Context, repoDirs []string, ignoreEmpty bool, args ...string) error {
c.CommandsCalled = append(c.CommandsCalled, "ListTags")

return c.Errors["ListTags"]
Expand Down
3 changes: 2 additions & 1 deletion cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {

tagCmd.Flags().BoolVarP(&list, "list", "l", false, "list tags in repositories with optional pattern")
tagCmd.Flags().BoolVarP(&del, "delete", "d", false, "delete tags in repositories")
tagCmd.Flags().BoolVar(&ignoreEmpty, "ignore-empty", false, "ignore repositories with no tags")
tagCmd.Flags().StringVarP(&message, "message", "m", "", "message for an annotated tag")
tagCmd.Flags().BoolVarP(&sign, "sign", "s", false, "create a GPG-signed tag (requires --message)")
tagCmd.Flags().BoolVar(&noSign, "no-sign", false, "do not GPG-sign the tag, overriding tag.gpgSign config")
Expand Down Expand Up @@ -83,7 +84,7 @@ func tagFunc(cmd *cobra.Command, args []string) error {
if list || len(args) == 0 {
args = append([]string{"--list"}, args...)

err = clt.ListTags(ctx, repoDirs, args...)
err = clt.ListTags(ctx, repoDirs, ignoreEmpty, args...)
if err != nil {
cmd.SilenceUsage = true
return fmt.Errorf("list tags: %w", err)
Expand Down
13 changes: 13 additions & 0 deletions cmd/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ func TestTag(t *testing.T) {
tc.AssertCommandsCalled(t, "GetDirs")
})

t.Run("lists tags with ignore-empty flag", func(t *testing.T) {
ignoreEmpty = true
t.Cleanup(func() { ignoreEmpty = false })

tc := testclient.New()
clt = tc

err := tagFunc(tagCmd, []string{})
assert.NoError(t, err)

tc.AssertCommandsCalled(t, "GetDirs", "ListTags")
})

t.Run("returns error on list tags failure", func(t *testing.T) {
tc := testclient.New()
tc.Errors["ListTags"] = errors.New("some list tags error")
Expand Down
Loading