aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-07 10:16:02 +0000
committerGravatar Runxi Yu2026-06-07 10:16:02 +0000
commit2f34ba9a792c3e0f4a5249d2e000cacbe73574fe (patch)
tree842cdf32cd1314d3d86252b49456abc435ea9537
parentinternal/testgit: Unexport Run and Command (diff)
signatureNo signature
internal/testgit: Prepare for tag
-rw-r--r--internal/testgit/command.go2
-rw-r--r--internal/testgit/commit.go11
-rw-r--r--internal/testgit/identity.go7
-rw-r--r--internal/testgit/revparse.go26
-rw-r--r--internal/testgit/tag.go46
5 files changed, 82 insertions, 10 deletions
diff --git a/internal/testgit/command.go b/internal/testgit/command.go
index 7f1835ec..db874bd1 100644
--- a/internal/testgit/command.go
+++ b/internal/testgit/command.go
@@ -25,7 +25,7 @@ func (repo *Repo) command(
func (repo *Repo) run(
tb testing.TB,
stdin io.Reader,
- command string,
+ command string, //nolint:unparam
args ...string,
) (stdout []byte, err error) {
tb.Helper()
diff --git a/internal/testgit/commit.go b/internal/testgit/commit.go
index 883db312..b1838e71 100644
--- a/internal/testgit/commit.go
+++ b/internal/testgit/commit.go
@@ -8,18 +8,11 @@ import (
"lindenii.org/go/furgit/object/id"
)
-// CommitTreeIdentity configures an author or committer identity
-// for [Repo.CommitTree].
-type CommitTreeIdentity struct {
- Name string
- Email string
-}
-
// CommitTreeOptions configures [Repo.CommitTree].
type CommitTreeOptions struct {
Message string
- Author CommitTreeIdentity
- Committer CommitTreeIdentity
+ Author Identity
+ Committer Identity
AuthorDate string
CommitterDate string
}
diff --git a/internal/testgit/identity.go b/internal/testgit/identity.go
new file mode 100644
index 00000000..1c155464
--- /dev/null
+++ b/internal/testgit/identity.go
@@ -0,0 +1,7 @@
+package testgit
+
+// Identity configures a Git identity.
+type Identity struct {
+ Name string
+ Email string
+}
diff --git a/internal/testgit/revparse.go b/internal/testgit/revparse.go
new file mode 100644
index 00000000..ffa5b702
--- /dev/null
+++ b/internal/testgit/revparse.go
@@ -0,0 +1,26 @@
+package testgit
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "lindenii.org/go/furgit/object/id"
+)
+
+// RevParse resolves one revision spec to an object ID.
+func (repo *Repo) RevParse(tb testing.TB, spec string) (id.ObjectID, error) {
+ tb.Helper()
+
+ stdout, err := repo.run(tb, nil, "git", "rev-parse", "--verify", "--end-of-options", spec)
+ if err != nil {
+ return id.ObjectID{}, fmt.Errorf("rev-parse %q: %w", spec, err)
+ }
+
+ objectID, err := repo.objectFormat.FromString(strings.TrimSuffix(string(stdout), "\n"))
+ if err != nil {
+ return id.ObjectID{}, fmt.Errorf("parse git rev-parse output %q: %w", string(stdout), err)
+ }
+
+ return objectID, nil
+}
diff --git a/internal/testgit/tag.go b/internal/testgit/tag.go
new file mode 100644
index 00000000..9aaac157
--- /dev/null
+++ b/internal/testgit/tag.go
@@ -0,0 +1,46 @@
+package testgit
+
+import (
+ "fmt"
+ "testing"
+
+ "lindenii.org/go/furgit/object/id"
+)
+
+// TagAnnotatedOptions configures [Repo.TagAnnotated].
+type TagAnnotatedOptions struct {
+ Message string
+ Tagger Identity
+ TaggerDate string
+}
+
+// TagAnnotated creates an annotated tag object and returns its object ID.
+func (repo *Repo) TagAnnotated(
+ tb testing.TB,
+ name string,
+ target id.ObjectID,
+ opts TagAnnotatedOptions,
+) (id.ObjectID, error) {
+ tb.Helper()
+
+ cmd := repo.command(tb, "git", "tag", "-a", "-m", opts.Message, "--end-of-options", name, target.String())
+
+ if opts.Tagger.Name != "" {
+ cmd.Env = setEnv(cmd.Env, "GIT_COMMITTER_NAME", opts.Tagger.Name)
+ }
+
+ if opts.Tagger.Email != "" {
+ cmd.Env = setEnv(cmd.Env, "GIT_COMMITTER_EMAIL", opts.Tagger.Email)
+ }
+
+ if opts.TaggerDate != "" {
+ cmd.Env = setEnv(cmd.Env, "GIT_COMMITTER_DATE", opts.TaggerDate)
+ }
+
+ err := cmd.Run()
+ if err != nil {
+ return id.ObjectID{}, fmt.Errorf("tag -a %q %s: %w", name, target, err)
+ }
+
+ return repo.RevParse(tb, "refs/tags/"+name)
+}