Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tag.go « testhelper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29e01e78cc0069ffb29c31424d21d2d5d643f70f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package testhelper

import (
	"bytes"
	"fmt"
	"strings"
	"testing"
)

// CreateTagOpts holds extra options for CreateTag.
type CreateTagOpts struct {
	Message string
}

// CreateTag creates a new tag.
func CreateTag(t *testing.T, repoPath, tagName, targetID string, opts *CreateTagOpts) string {
	var message string

	if opts != nil {
		if opts.Message != "" {
			message = opts.Message
		}
	}

	committerName := "Scrooge McDuck"
	committerEmail := "scrooge@mcduck.com"

	// message can be very large, passing it directly in args would blow things up!
	stdin := bytes.NewBufferString(message)

	args := []string{"-C", repoPath,
		"-c", fmt.Sprintf("user.name=%s", committerName),
		"-c", fmt.Sprintf("user.email=%s", committerEmail),
		"tag",
	}
	if message != "" {
		args = append(args, "-F", "-")
	}
	args = append(args, tagName, targetID)

	MustRunCommand(t, stdin, "git", args...)

	tagID := MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", tagName)
	return strings.TrimSpace(string(tagID))
}