diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-06-27 11:39:03 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-06-30 16:43:11 +0300 |
commit | 712b2ff9b2e8c20726344b479f778c3cac29b45b (patch) | |
tree | 1bf91da4cbda273ab357559c33f1181f8f9d861e | |
parent | c54d613d0eb9c573d79f5da0975655f11f007932 (diff) |
gittest: Add helper to resolve revisions to an object ID
Add helper function to resolve revisions to an object ID, which is a
frequently used pattern in our tests.
-rw-r--r-- | internal/git/gittest/ref.go | 11 | ||||
-rw-r--r-- | internal/git/gittest/ref_test.go | 17 |
2 files changed, 28 insertions, 0 deletions
diff --git a/internal/git/gittest/ref.go b/internal/git/gittest/ref.go index aedbcf3b6..bb1e5a104 100644 --- a/internal/git/gittest/ref.go +++ b/internal/git/gittest/ref.go @@ -3,11 +3,22 @@ package gittest import ( "testing" + "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/v15/internal/helper/text" ) // WriteRef writes a reference into the repository pointing to the given object ID. func WriteRef(t testing.TB, cfg config.Cfg, repoPath string, ref git.ReferenceName, oid git.ObjectID) { Exec(t, cfg, "-C", repoPath, "update-ref", ref.String(), oid.String()) } + +// ResolveRevision resolves the revision to an object ID. +func ResolveRevision(t testing.TB, cfg config.Cfg, repoPath string, revision string) git.ObjectID { + t.Helper() + output := Exec(t, cfg, "-C", repoPath, "rev-parse", "--verify", revision) + objectID, err := git.NewObjectIDFromHex(text.ChompBytes(output)) + require.NoError(t, err) + return objectID +} diff --git a/internal/git/gittest/ref_test.go b/internal/git/gittest/ref_test.go new file mode 100644 index 000000000..eed9287ee --- /dev/null +++ b/internal/git/gittest/ref_test.go @@ -0,0 +1,17 @@ +package gittest + +import ( + "testing" + + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v15/internal/git" +) + +func TestResolveRevision(t *testing.T) { + cfg, _, repoPath := setup(t) + + require.Equal(t, + git.ObjectID("1e292f8fedd741b75372e19097c76d327140c312"), + ResolveRevision(t, cfg, repoPath, "refs/heads/master"), + ) +} |