Git designed for AI agents.
operations: a start reference that is not a commit still loses to the branch
Federico Eliaab3a4b47b8f2
diff --git a/internal/gitaly/service/operations/branch_exact_test.go b/internal/gitaly/service/operations/branch_exact_test.goindex 93ab216..9505ecd 100644--- a/internal/gitaly/service/operations/branch_exact_test.go+++ b/internal/gitaly/service/operations/branch_exact_test.go@@ -926,6 +926,15 @@ func TestStartBranchLocalAndRemoteAgree(t *testing.T) {return setup.base.String()},},+ {+ desc: "a branch and a tag of its name at a tree",+ refs: func(t *testing.T, setup cherryPickOrRevertSetup) string {+ tree := strings.TrimSpace(string(gittest.Exec(t, cfg, "-C", setup.repoPath, "rev-parse", setup.base.String()+"^{tree}")))+ gittest.WriteRef(t, cfg, setup.repoPath, "refs/tags/x", git.ObjectID(tree))+ gittest.WriteRef(t, cfg, setup.repoPath, "refs/heads/x", setup.base)+ return setup.base.String()+ },+ },{desc: "a tag at a tree, before a remote-tracking branch",refs: func(t *testing.T, setup cherryPickOrRevertSetup) string {@@ -1027,6 +1036,8 @@ func TestResolveStartBranch(t *testing.T) {// A path is not a start point; a colon inside braces is not a path.{name: "main:file", refs: []string{"refs/heads/main"}, expected: "path"},{name: ":path", expected: "path", noLookup: true},+ // A search of the commit messages is refused too, by choice.+ {name: ":/fix the bug", expected: "path", noLookup: true},{name: "main^{/fix: x}", refs: []string{"refs/heads/main"}, expected: "v(refs/heads/main)^{/fix: x}^{commit}"},{name: "main@{2024-01-01 10:00:00}",diff --git a/internal/gitaly/service/operations/revert.go b/internal/gitaly/service/operations/revert.goindex dcc50df..d1104dd 100644--- a/internal/gitaly/service/operations/revert.go+++ b/internal/gitaly/service/operations/revert.go@@ -226,6 +226,11 @@ func (s *Server) UserRevert(ctx context.Context, req *gitalypb.UserRevertRequest// start point, as before. A full reference name (refs/...) is read exactly as given, with no// fallback: a missing refs/heads/x does not resolve through refs/refs/heads/x or another decoy.//+// A start point is a commit, never a path: <revision>:path is refused, and so is :/<text>, a search+// of the commit messages, by choice, as a start point that depends on which message matches is+// fragile. Through a start repository, FindCommit refuses revisions that hold whitespace or a colon,+// so main@{2024-01-01 10:00:00} or main^{/fix: x} work locally only.+//// The chosen reference is read once, to its value, and the suffix applies to that object ID: no// rule resolves the name again, so a reference that is dangling, or that goes away meanwhile, never// yields a decoy. A reflog suffix (@{n}) needs the name: the reference must have a reflog of its@@ -341,19 +346,19 @@ func startReference(name string, read func(git.ReferenceName) (git.ObjectID, errif errors.Is(err, git.ErrReferenceNotFound) {continue}- if err != nil {+ // A reference that does not point to a commit exists all the same, as it does when its+ // value is read locally: the branch may still beat it, and it fails the request only+ // when it is the reference chosen.+ if err != nil && !errors.Is(err, remoterepo.ErrNotACommit) {return "", "", err}if !namesNamespace && (candidate == other || candidate == tag) {- branchValue, err := read(branch)- if err == nil {- return branch, branchValue, nil- }- if !errors.Is(err, git.ErrReferenceNotFound) {- return "", "", err+ branchValue, branchErr := read(branch)+ if !errors.Is(branchErr, git.ErrReferenceNotFound) {+ return branch, branchValue, branchErr}}- return candidate, value, nil+ return candidate, value, err}return "", "", nil}