diff --git a/commands/ci/status/status.go b/commands/ci/status/status.go index 69084c9b55dc20386d442b80655d53c10d8ae8b5..58b243e4f2c07541852d0f6e8a58780183e88cb7 100644 --- a/commands/ci/status/status.go +++ b/commands/ci/status/status.go @@ -7,7 +7,6 @@ import ( "gitlab.com/gitlab-org/cli/api" "gitlab.com/gitlab-org/cli/commands/ci/ciutils" "gitlab.com/gitlab-org/cli/commands/cmdutils" - "gitlab.com/gitlab-org/cli/internal/glrepo" "gitlab.com/gitlab-org/cli/pkg/dbg" "gitlab.com/gitlab-org/cli/pkg/git" "gitlab.com/gitlab-org/cli/pkg/utils" @@ -38,7 +37,6 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { Long: ``, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - var err error c := f.IO.Color() apiClient, err := f.HttpClient() @@ -46,19 +44,27 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { return err } + repo, err := f.BaseRepo() + if err != nil { + return err + } + branch, _ := cmd.Flags().GetString("branch") live, _ := cmd.Flags().GetBool("live") compact, _ := cmd.Flags().GetBool("compact") + repoName := repo.FullName() + dbg.Debug("Repository:", repoName) + if branch == "" { branch, err = git.CurrentBranch() if err != nil { - return err + // if there isn't a branch via --branch, and we are not in a git repository set the branch to main + branch = "main" } dbg.Debug("Current branch:", branch) } - var repo glrepo.Interface branchConfig := git.ReadBranchConfig(branch) if branchConfig.RemoteName == "" { repo, err = f.BaseRepo() @@ -77,8 +83,8 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { return err } } - repoName := repo.FullName() - dbg.Debug("Repository:", repoName) + + dbg.Debug("Current branch:", branch) runningPipeline, err := api.GetLatestPipeline(apiClient, repoName, branch) if err != nil { @@ -187,7 +193,7 @@ func NewCmdStatus(f *cmdutils.Factory) *cobra.Command { pipelineStatusCmd.Flags().BoolP("live", "l", false, "Show status in real time until the pipeline ends.") pipelineStatusCmd.Flags().BoolP("compact", "c", false, "Show status in compact format.") - pipelineStatusCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch. Default: current branch.") + pipelineStatusCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch.") return pipelineStatusCmd } diff --git a/docs/source/ci/status.md b/docs/source/ci/status.md index ee451526736c4523cb5651f746c38a01e64932e8..d38614e6aa7ef508fff8c96ff7b1cd883c13879c 100644 --- a/docs/source/ci/status.md +++ b/docs/source/ci/status.md @@ -42,7 +42,7 @@ glab ci status ## Options ```plaintext - -b, --branch string Check pipeline status for a branch. Default: current branch. + -b, --branch string Check pipeline status for a branch. -c, --compact Show status in compact format. -l, --live Show status in real time until the pipeline ends. ```