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

Function gitTagInfo

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

Source from the content-addressed store, hash-verified

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