From f9bf27d5777b702d502243eccdc419350a6250d7 Mon Sep 17 00:00:00 2001 From: dan9186 Date: Thu, 4 Jun 2026 10:51:08 -0700 Subject: [PATCH] wire ignore empty through to list tags --- client/clienter.go | 2 +- client/repos/tag.go | 9 +++++++-- client/testclient/client.go | 2 +- cmd/tag.go | 3 ++- cmd/tag_test.go | 13 +++++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/client/clienter.go b/client/clienter.go index 1f01ad2..69b542d 100644 --- a/client/clienter.go +++ b/client/clienter.go @@ -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 diff --git a/client/repos/tag.go b/client/repos/tag.go index 128e016..9c53c16 100644 --- a/client/repos/tag.go +++ b/client/repos/tag.go @@ -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) @@ -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) diff --git a/client/testclient/client.go b/client/testclient/client.go index d17753e..782a72f 100644 --- a/client/testclient/client.go +++ b/client/testclient/client.go @@ -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"] diff --git a/cmd/tag.go b/cmd/tag.go index 623149b..3c461c9 100644 --- a/cmd/tag.go +++ b/cmd/tag.go @@ -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") @@ -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) diff --git a/cmd/tag_test.go b/cmd/tag_test.go index 98729f0..0fa913a 100644 --- a/cmd/tag_test.go +++ b/cmd/tag_test.go @@ -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")