diff --git a/knotmirror/xrpc/gitea/batch.go b/knotmirror/xrpc/gitea/batch.go index 4008a84b..07a33615 100644 --- a/knotmirror/xrpc/gitea/batch.go +++ b/knotmirror/xrpc/gitea/batch.go @@ -25,7 +25,7 @@ func GetCommit(ctx context.Context, repoPath, rev string) (*object.Commit, error wr, rd, cancel := CatFileBatch(ctx, repoPath) defer cancel() - if _, err := wr.Write([]byte(rev + "\n")); err != nil { + if _, err := wr.Write([]byte(rev + "^{commit}\n")); err != nil { return nil, fmt.Errorf("write rev: %w", err) } sha, typ, size, err := ReadBatchLine(rd) diff --git a/knotmirror/xrpc/gitea/commit_test.go b/knotmirror/xrpc/gitea/commit_test.go index 1b578866..59ce063c 100644 --- a/knotmirror/xrpc/gitea/commit_test.go +++ b/knotmirror/xrpc/gitea/commit_test.go @@ -4,6 +4,10 @@ package gitea import ( + "context" + "os" + "os/exec" + "path/filepath" "strings" "testing" @@ -13,6 +17,31 @@ import ( "tangled.org/core/types" ) +func TestGetCommitDereferencesAnnotatedTag(t *testing.T) { + repo := t.TempDir() + runGit := func(args ...string) []byte { + t.Helper() + cmd := exec.Command("git", args...) + cmd.Dir = repo + out, err := cmd.CombinedOutput() + require.NoError(t, err, string(out)) + return out + } + + runGit("init") + runGit("config", "user.name", "test") + runGit("config", "user.email", "test@example.com") + require.NoError(t, os.WriteFile(filepath.Join(repo, "file.txt"), []byte("hello\n"), 0o644)) + runGit("add", "file.txt") + runGit("commit", "-m", "initial") + runGit("tag", "-a", "v0.1.0", "-m", "release") + + want := strings.TrimSpace(string(runGit("rev-parse", "v0.1.0^{commit}"))) + commit, err := GetCommit(context.Background(), repo, "v0.1.0") + require.NoError(t, err) + assert.Equal(t, want, commit.Hash.String()) +} + func TestCommitFromReader(t *testing.T) { commitString := `tree f1a6cb52b2d16773290cefe49ad0684b50a4f930 parent 37991dec2c8e592043f47155ce4808d4580f9123