MCPcopy Create free account
hub / github.com/cli/cli / gitTagInfo

Function gitTagInfo

pkg/cmd/release/create/create.go:571–604  ·  view source on GitHub ↗
(client *git.Client, tagName string)

Source from the content-addressed store, hash-verified

569}
570
571func gitTagInfo(client *git.Client, tagName string) (string, error) {
572 contentCmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents)")
573 if err != nil {
574 return "", err
575 }
576 content, err := contentCmd.Output()
577 if err != nil {
578 return "", err
579 }
580
581 // If there is a signature, we should strip it from the end of the content.
582 // Note that, we can achieve this by looking for markers like "-----BEGIN PGP
583 // SIGNATURE-----" and cut the remaining text from the content, but this is
584 // not a safe approach, because, although unlikely, the content can contain
585 // a signature-like section which we shouldn't leave it as is. So, we need
586 // to get the tag signature as a whole, if any, and remote it from the content.
587 signatureCmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents:signature)")
588 if err != nil {
589 return "", err
590 }
591 signature, err := signatureCmd.Output()
592 if err != nil {
593 return "", err
594 }
595
596 if len(signature) == 0 {
597 // The tag annotation content has no trailing signature to strip out,
598 // so we return the entire content.
599 return string(content), nil
600 }
601
602 body, _ := strings.CutSuffix(string(content), "\n"+string(signature))
603 return body, nil
604}
605
606func detectPreviousTag(client *git.Client, headRef string) (string, error) {
607 cmd, err := client.Command(context.Background(), "describe", "--tags", "--abbrev=0", fmt.Sprintf("%s^", headRef))

Callers 2

Test_gitTagInfoFunction · 0.85
createRunFunction · 0.85

Calls 2

CommandMethod · 0.80
OutputMethod · 0.65

Tested by 1

Test_gitTagInfoFunction · 0.68