diff options
author | James Fargher <jfargher@gitlab.com> | 2022-10-19 02:08:02 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2022-10-21 02:04:47 +0300 |
commit | 8de8e0c5ea68e1ed182353fb279a7f190acc3074 (patch) | |
tree | 48e44ecb8ec9c444fdd70a393d9319297bca8217 | |
parent | faa097a0d42a9338445700a52aac25ba5887fd85 (diff) |
localrepo: Make GetReference return the name of a conflicting ref
This error does not only happen when the reference name given is not
specific enough, it can also happen when a ref has a path segments the
same as an existing ref. In this case it is useful to specify at least
one of the conflicting refs to reduce the time required to debug such
errors.
-rw-r--r-- | internal/git/localrepo/refs.go | 2 | ||||
-rw-r--r-- | internal/git/localrepo/refs_test.go | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/internal/git/localrepo/refs.go b/internal/git/localrepo/refs.go index f76975e28..0c8e4a29a 100644 --- a/internal/git/localrepo/refs.go +++ b/internal/git/localrepo/refs.go @@ -82,7 +82,7 @@ func (repo *Repo) GetReference(ctx context.Context, reference git.ReferenceName) return git.Reference{}, git.ErrReferenceNotFound } if refs[0].Name != reference { - return git.Reference{}, git.ErrReferenceAmbiguous + return git.Reference{}, fmt.Errorf("%w: conflicts with %q", git.ErrReferenceAmbiguous, refs[0].Name) } return refs[0], nil diff --git a/internal/git/localrepo/refs_test.go b/internal/git/localrepo/refs_test.go index 47f64c3ab..7a9bafcc0 100644 --- a/internal/git/localrepo/refs_test.go +++ b/internal/git/localrepo/refs_test.go @@ -96,7 +96,7 @@ func TestRepo_GetReference(t *testing.T) { { desc: "prefix returns an error", ref: "refs/heads", - expectedErr: git.ErrReferenceAmbiguous, + expectedErr: fmt.Errorf("%w: conflicts with %q", git.ErrReferenceAmbiguous, "refs/heads/master"), }, { desc: "nonexistent branch", |