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
46
47
48
49
50
51
52
53
54
55
|
package gittest
import (
"bytes"
"fmt"
"testing"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper/text"
)
// CreateTagOpts holds extra options for CreateTag.
type CreateTagOpts struct {
Message string
Force bool
}
// CreateTag creates a new tag.
func CreateTag(t testing.TB, cfg config.Cfg, repoPath, tagName, targetID string, opts *CreateTagOpts) string {
var message string
force := false
if opts != nil {
if opts.Message != "" {
message = opts.Message
}
force = opts.Force
}
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 force {
args = append(args, "-f")
}
if message != "" {
args = append(args, "-F", "-")
}
args = append(args, tagName, targetID)
ExecStream(t, cfg, stdin, args...)
tagID := Exec(t, cfg, "-C", repoPath, "show-ref", "-s", tagName)
return text.ChompBytes(tagID)
}
|