Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-29 11:27:14 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-05 07:56:26 +0300
commit094b679d538589f0f0babfc0ed7d542c2de82445 (patch)
tree97f2aaa5895d6f56f7afeabee182b5595b71a88b
parent2d4fec64be694daebf0e341ba0d2b809572a7aa1 (diff)
updateref: Convert tests to not use a seeded repository
Convert the tests of the updateref package to not use a seeded repository so that we can test the package with both SHA1 and SHA256 object hashes.
-rw-r--r--internal/git/updateref/update_with_hooks_test.go72
-rw-r--r--internal/git/updateref/updateref_test.go201
2 files changed, 137 insertions, 136 deletions
diff --git a/internal/git/updateref/update_with_hooks_test.go b/internal/git/updateref/update_with_hooks_test.go
index 7bd5a2e2b..f1a504167 100644
--- a/internal/git/updateref/update_with_hooks_test.go
+++ b/internal/git/updateref/update_with_hooks_test.go
@@ -29,18 +29,14 @@ import (
)
func TestUpdaterWithHooks_UpdateReference_invalidParameters(t *testing.T) {
- ctx := testhelper.Context(t)
-
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+ t.Parallel()
- user := &gitalypb.User{
- GlId: "1234",
- GlUsername: "Username",
- Name: []byte("Name"),
- Email: []byte("mail@example.com"),
- }
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+ repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0])
- revA, revB := git.ObjectID(strings.Repeat("a", 40)), git.ObjectID(strings.Repeat("b", 40))
+ revA := git.ObjectID(strings.Repeat("a", gittest.DefaultObjectHash.EncodedLen()))
+ revB := git.ObjectID(strings.Repeat("b", gittest.DefaultObjectHash.EncodedLen()))
updater := updateref.NewUpdaterWithHooks(cfg, nil, &hook.MockManager{}, nil, nil)
@@ -86,16 +82,17 @@ func TestUpdaterWithHooks_UpdateReference_invalidParameters(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- err := updater.UpdateReference(ctx, repo, user, nil, tc.ref, tc.newRev, tc.oldRev)
+ err := updater.UpdateReference(ctx, repo, gittest.TestUser, nil, tc.ref, tc.newRev, tc.oldRev)
require.Equal(t, tc.expectedErr, err)
})
}
}
func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
- ctx := testhelper.Context(t)
+ t.Parallel()
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
// We need to set up a separate "real" hook service here, as it will be used in
// git-update-ref(1) spawned by `updateRefWithHooks()`
@@ -103,21 +100,15 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
gitalypb.RegisterHookServiceServer(srv, hookservice.NewServer(deps.GetHookManager(), deps.GetGitCmdFactory(), deps.GetPackObjectsCache(), deps.GetPackObjectsConcurrencyTracker()))
})
- user := &gitalypb.User{
- GlId: "1234",
- GlUsername: "Username",
- Name: []byte("Name"),
- Email: []byte("mail@example.com"),
- }
-
- oldRev := "1e292f8fedd741b75372e19097c76d327140c312"
+ repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
requirePayload := func(t *testing.T, env []string) {
require.Len(t, env, 1)
expectedPayload := git.NewHooksPayload(cfg, repo, nil, &git.UserDetails{
- UserID: "1234",
- Username: "Username",
+ UserID: gittest.TestUser.GlId,
+ Username: gittest.TestUser.GlUsername,
Protocol: "web",
}, git.ReceivePackHooks, featureflag.FromContext(ctx))
@@ -147,14 +138,14 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
preReceive: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
- require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
+ require.Equal(t, fmt.Sprintf("%s %s refs/heads/main\n", commitID, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
require.Empty(t, pushOptions)
requirePayload(t, env)
return nil
},
update: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error {
- require.Equal(t, "refs/heads/master", ref)
- require.Equal(t, oldRev, oldValue)
+ require.Equal(t, "refs/heads/main", ref)
+ require.Equal(t, commitID.String(), oldValue)
require.Equal(t, newValue, git.ObjectHashSHA1.ZeroOID.String())
requirePayload(t, env)
return nil
@@ -162,7 +153,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
postReceive: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
- require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
+ require.Equal(t, fmt.Sprintf("%s %s refs/heads/main\n", commitID.String(), git.ObjectHashSHA1.ZeroOID.String()), string(changes))
requirePayload(t, env)
require.Empty(t, pushOptions)
return nil
@@ -170,7 +161,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
referenceTransaction: func(t *testing.T, ctx context.Context, state hook.ReferenceTransactionState, env []string, stdin io.Reader) error {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
- require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
+ require.Equal(t, fmt.Sprintf("%s %s refs/heads/main\n", commitID.String(), git.ObjectHashSHA1.ZeroOID.String()), string(changes))
require.Less(t, referenceTransactionCalls, 2)
if referenceTransactionCalls == 0 {
@@ -257,7 +248,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
updater := updateref.NewUpdaterWithHooks(cfg, config.NewLocator(cfg), hookManager, gitCmdFactory, nil)
- err := updater.UpdateReference(ctx, repo, user, nil, git.ReferenceName("refs/heads/master"), git.ObjectHashSHA1.ZeroOID, git.ObjectID(oldRev))
+ err := updater.UpdateReference(ctx, repo, gittest.TestUser, nil, git.ReferenceName("refs/heads/main"), git.ObjectHashSHA1.ZeroOID, commitID)
if tc.expectedErr == "" {
require.NoError(t, err)
} else {
@@ -265,24 +256,29 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
}
if tc.expectedRefDeletion {
- contained, err := localrepo.NewTestRepo(t, cfg, repo).HasRevision(ctx, git.Revision("refs/heads/master"))
+ contained, err := localrepo.NewTestRepo(t, cfg, repo).HasRevision(ctx, git.Revision("refs/heads/main"))
require.NoError(t, err)
require.False(t, contained, "branch should have been deleted")
- gittest.Exec(t, cfg, "-C", repoPath, "branch", "master", oldRev)
+ gittest.Exec(t, cfg, "-C", repoPath, "branch", "main", commitID.String())
} else {
- ref, err := localrepo.NewTestRepo(t, cfg, repo).GetReference(ctx, "refs/heads/master")
+ ref, err := localrepo.NewTestRepo(t, cfg, repo).GetReference(ctx, "refs/heads/main")
require.NoError(t, err)
- require.Equal(t, ref.Target, oldRev)
+ require.Equal(t, ref.Target, commitID.String())
}
})
}
}
func TestUpdaterWithHooks_quarantine(t *testing.T) {
- cfg, repoProto, _ := testcfg.BuildWithRepo(t)
+ t.Parallel()
+
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
locator := config.NewLocator(cfg)
- ctx := testhelper.Context(t)
+
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
unquarantinedRepo := localrepo.NewTestRepo(t, cfg, repoProto)
@@ -366,9 +362,9 @@ func TestUpdaterWithHooks_quarantine(t *testing.T) {
Email: []byte("mail@example.com"),
},
quarantine,
- git.ReferenceName("refs/heads/master"),
+ git.ReferenceName("refs/heads/main"),
git.ObjectHashSHA1.ZeroOID,
- git.ObjectID("1e292f8fedd741b75372e19097c76d327140c312"),
+ commitID,
))
require.Equal(t, map[string]int{
@@ -379,7 +375,7 @@ func TestUpdaterWithHooks_quarantine(t *testing.T) {
"commit": 1,
}, hookExecutions)
- contained, err := unquarantinedRepo.HasRevision(ctx, git.Revision("refs/heads/master"))
+ contained, err := unquarantinedRepo.HasRevision(ctx, git.Revision("refs/heads/main"))
require.NoError(t, err)
require.False(t, contained, "branch should have been deleted")
}
diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go
index 6bfd06778..1e2185c45 100644
--- a/internal/git/updateref/updateref_test.go
+++ b/internal/git/updateref/updateref_test.go
@@ -21,17 +21,18 @@ func TestMain(m *testing.M) {
testhelper.Run(m)
}
-func setupUpdater(t *testing.T, ctx context.Context) (config.Cfg, *localrepo.Repo, *Updater) {
+func setupUpdater(t *testing.T, ctx context.Context) (config.Cfg, *localrepo.Repo, string, *Updater) {
t.Helper()
- cfg, protoRepo, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
- repo := localrepo.NewTestRepo(t, cfg, protoRepo, git.WithSkipHooks())
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repo := localrepo.NewTestRepo(t, cfg, repoProto, git.WithSkipHooks())
updater, err := New(ctx, repo)
require.NoError(t, err)
- return cfg, repo, updater
+ return cfg, repo, repoPath, updater
}
func TestUpdater_create(t *testing.T) {
@@ -39,21 +40,16 @@ func TestUpdater_create(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, updater := setupUpdater(t, ctx)
+ cfg, _, repoPath, updater := setupUpdater(t, ctx)
- headCommit, err := repo.ReadCommit(ctx, "HEAD")
- require.NoError(t, err)
-
- ref := git.ReferenceName("refs/heads/_create")
- sha := headCommit.Id
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
- require.NoError(t, updater.Create(ref, sha))
+ require.NoError(t, updater.Create("refs/heads/_create", commitID.String()))
require.NoError(t, updater.Commit())
- // check the ref was created
- commit, logErr := repo.ReadCommit(ctx, ref.Revision())
- require.NoError(t, logErr)
- require.Equal(t, commit.Id, sha, "reference was created with the wrong SHA")
+ // Verify that the reference was created as expected and that it points to the correct
+ // commit.
+ require.Equal(t, gittest.ResolveRevision(t, cfg, repoPath, "refs/heads/_create"), commitID)
}
func TestUpdater_update(t *testing.T) {
@@ -61,37 +57,36 @@ func TestUpdater_update(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, updater := setupUpdater(t, ctx)
-
- headCommit, err := repo.ReadCommit(ctx, "HEAD")
- require.NoError(t, err)
-
- ref := git.ReferenceName("refs/heads/feature")
- sha := headCommit.Id
+ cfg, repo, repoPath, _ := setupUpdater(t, ctx)
- // Sanity check: ensure the ref exists before we start
- commit, logErr := repo.ReadCommit(ctx, ref.Revision())
- require.NoError(t, logErr)
- require.NotEqual(t, commit.Id, sha, "%s points to HEAD: %s in the test repository", ref.String(), sha)
+ oldCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
+ newCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(oldCommitID))
+ otherCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("other"))
- require.NoError(t, updater.Update(ref, sha, ""))
- require.NoError(t, updater.Prepare())
+ // Check that we can force-update the reference when we don't give an old object ID.
+ updater, err := New(ctx, repo)
+ require.NoError(t, err)
+ require.NoError(t, updater.Update("refs/heads/main", newCommitID.String(), ""))
require.NoError(t, updater.Commit())
+ require.Equal(t, gittest.ResolveRevision(t, cfg, repoPath, "refs/heads/main"), newCommitID)
- // check the ref was updated
- commit, logErr = repo.ReadCommit(ctx, ref.Revision())
- require.NoError(t, logErr)
- require.Equal(t, commit.Id, sha, "reference was not updated")
+ // Check that we can update with safety guards when giving an old commit ID.
+ updater, err = New(ctx, repo)
+ require.NoError(t, err)
+ require.NoError(t, updater.Update("refs/heads/main", oldCommitID.String(), newCommitID.String()))
+ require.NoError(t, updater.Commit())
+ require.Equal(t, gittest.ResolveRevision(t, cfg, repoPath, "refs/heads/main"), oldCommitID)
- // since ref has been updated to HEAD, we know that it does not point to HEAD^. So, HEAD^ is an invalid "old value" for updating ref
- parentCommit, err := repo.ReadCommit(ctx, "HEAD^")
+ // And finally assert that we fail to update the reference in case we're trying to update
+ // when the old commit ID doesn't match.
+ updater, err = New(ctx, repo)
require.NoError(t, err)
- require.Error(t, updater.Update(ref, parentCommit.Id, parentCommit.Id))
+ require.NoError(t, updater.Update("refs/heads/main", newCommitID.String(), otherCommitID.String()))
+ err = updater.Commit()
+ require.Error(t, err)
+ require.Contains(t, err.Error(), fmt.Sprintf("fatal: commit: cannot lock ref 'refs/heads/main': is at %s but expected %s", oldCommitID, otherCommitID))
- // check the ref was not updated
- commit, logErr = repo.ReadCommit(ctx, ref.Revision())
- require.NoError(t, logErr)
- require.NotEqual(t, commit.Id, parentCommit.Id, "reference was updated when it shouldn't have been")
+ require.Equal(t, gittest.ResolveRevision(t, cfg, repoPath, "refs/heads/main"), oldCommitID)
}
func TestUpdater_delete(t *testing.T) {
@@ -99,16 +94,16 @@ func TestUpdater_delete(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, updater := setupUpdater(t, ctx)
+ cfg, repo, repoPath, updater := setupUpdater(t, ctx)
- ref := git.ReferenceName("refs/heads/feature")
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
- require.NoError(t, updater.Delete(ref))
+ require.NoError(t, updater.Delete("refs/heads/main"))
require.NoError(t, updater.Commit())
- // check the ref was removed
- _, err := repo.ReadCommit(ctx, ref.Revision())
- require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
+ // Check that the reference was removed.
+ _, err := repo.ReadCommit(ctx, "refs/heads/main")
+ require.Equal(t, localrepo.ErrObjectNotFound, err)
}
func TestUpdater_prepareLocksTransaction(t *testing.T) {
@@ -116,14 +111,13 @@ func TestUpdater_prepareLocksTransaction(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, updater := setupUpdater(t, ctx)
+ cfg, _, repoPath, updater := setupUpdater(t, ctx)
- commit, logErr := repo.ReadCommit(ctx, "refs/heads/master")
- require.NoError(t, logErr)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
- require.NoError(t, updater.Update("refs/heads/feature", commit.Id, ""))
+ require.NoError(t, updater.Update("refs/heads/feature", commitID.String(), ""))
require.NoError(t, updater.Prepare())
- require.NoError(t, updater.Update("refs/heads/feature", commit.Id, ""))
+ require.NoError(t, updater.Update("refs/heads/feature", commitID.String(), ""))
err := updater.Commit()
require.Error(t, err, "cannot update after prepare")
@@ -133,27 +127,33 @@ func TestUpdater_prepareLocksTransaction(t *testing.T) {
func TestUpdater_concurrentLocking(t *testing.T) {
t.Parallel()
- cfg, protoRepo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
if !gittest.GitSupportsStatusFlushing(t, ctx, cfg) {
t.Skip("git does not support flushing yet, which is known to be flaky")
}
- repo := localrepo.NewTestRepo(t, cfg, protoRepo, git.WithSkipHooks())
+ repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ repo := localrepo.NewTestRepo(t, cfg, repoProto, git.WithSkipHooks())
- commit, logErr := repo.ReadCommit(ctx, "refs/heads/master")
- require.NoError(t, logErr)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
+ // Create the first updater that prepares the reference transaction so that the reference
+ // we're about to update is locked.
firstUpdater, err := New(ctx, repo)
require.NoError(t, err)
- require.NoError(t, firstUpdater.Update("refs/heads/master", "", commit.Id))
+ require.NoError(t, firstUpdater.Update("refs/heads/master", commitID.String(), ""))
require.NoError(t, firstUpdater.Prepare())
+ // Now we create a second updater that tries to update the same reference.
secondUpdater, err := New(ctx, repo)
require.NoError(t, err)
- require.NoError(t, secondUpdater.Update("refs/heads/master", "", commit.Id))
+ require.NoError(t, secondUpdater.Update("refs/heads/master", commitID.String(), ""))
+ // Preparing this second updater should fail though because we notice that the reference is
+ // locked.
err = secondUpdater.Prepare()
var errAlreadyLocked *ErrAlreadyLocked
require.ErrorAs(t, err, &errAlreadyLocked)
@@ -161,6 +161,7 @@ func TestUpdater_concurrentLocking(t *testing.T) {
Ref: "refs/heads/master",
})
+ // Whereas committing the first transaction should succeed.
require.NoError(t, firstUpdater.Commit())
}
@@ -169,49 +170,53 @@ func TestUpdater_bulkOperation(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, updater := setupUpdater(t, ctx)
+ cfg, repo, repoPath, updater := setupUpdater(t, ctx)
- headCommit, err := repo.ReadCommit(ctx, "HEAD")
- require.NoError(t, err)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
+ var expectedRefs []git.Reference
for i := 0; i < 1000; i++ {
- ref := fmt.Sprintf("refs/head/_test_%d", i)
- require.NoError(t, updater.Create(git.ReferenceName(ref), headCommit.Id), "Failed to create ref %d", i)
+ reference := git.Reference{
+ Name: git.ReferenceName(fmt.Sprintf("refs/head/test_%d", i)),
+ Target: commitID.String(),
+ }
+
+ require.NoError(t, updater.Create(reference.Name, commitID.String()))
+ expectedRefs = append(expectedRefs, reference)
}
require.NoError(t, updater.Commit())
refs, err := repo.GetReferences(ctx, "refs/")
require.NoError(t, err)
- require.Greater(t, len(refs), 1000, "At least 1000 refs should be present")
+ require.ElementsMatch(t, expectedRefs, refs)
}
func TestUpdater_contextCancellation(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
+ childCtx, childCancel := context.WithCancel(ctx)
- cfg, repo, _ := setupUpdater(t, ctx)
+ cfg, repoProto, repoPath, _ := setupUpdater(t, ctx)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
- headCommit, err := repo.ReadCommit(ctx, "HEAD")
- require.NoError(t, err)
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
- childCtx, childCancel := context.WithCancel(ctx)
- localRepo := localrepo.NewTestRepo(t, cfg, repo)
- updater, err := New(childCtx, localRepo)
+ updater, err := New(childCtx, repo)
require.NoError(t, err)
- ref := git.ReferenceName("refs/heads/_shouldnotexist")
-
- require.NoError(t, updater.Create(ref, headCommit.Id))
+ require.NoError(t, updater.Create("refs/heads/main", commitID.String()))
- // Force the update-ref process to terminate early
+ // Force the update-ref process to terminate early by cancelling the context.
childCancel()
+
+ // We should see that committing the update fails now.
require.Error(t, updater.Commit())
- // check the ref doesn't exist
- _, err = repo.ReadCommit(ctx, ref.Revision())
- require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
+ // And the reference should not have been created.
+ _, err = repo.ReadCommit(ctx, "refs/heads/main")
+ require.Equal(t, localrepo.ErrObjectNotFound, err)
}
func TestUpdater_cancel(t *testing.T) {
@@ -219,22 +224,26 @@ func TestUpdater_cancel(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repo, updater := setupUpdater(t, ctx)
+ cfg, repo, repoPath, updater := setupUpdater(t, ctx)
if !gittest.GitSupportsStatusFlushing(t, ctx, cfg) {
t.Skip("git does not support flushing yet, which is known to be flaky")
}
- require.NoError(t, updater.Delete(git.ReferenceName("refs/heads/master")))
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"))
+
+ // Queue the branch for deletion and lock it.
+ require.NoError(t, updater.Delete(git.ReferenceName("refs/heads/main")))
require.NoError(t, updater.Prepare())
- // A concurrent update shouldn't be allowed.
+ // Try to delete the same reference via a concurrent updater. This should not be allowed
+ // because the reference is locked already.
concurrentUpdater, err := New(ctx, repo)
require.NoError(t, err)
- require.NoError(t, concurrentUpdater.Delete(git.ReferenceName("refs/heads/master")))
+ require.NoError(t, concurrentUpdater.Delete(git.ReferenceName("refs/heads/main")))
err = concurrentUpdater.Commit()
- require.NotNil(t, err)
- require.Contains(t, err.Error(), "fatal: commit: cannot lock ref 'refs/heads/master'")
+ require.Error(t, err)
+ require.Contains(t, err.Error(), "fatal: commit: cannot lock ref 'refs/heads/main'")
// We now cancel the initial updater. Afterwards, it should be possible again to update the
// ref because locks should have been released.
@@ -242,7 +251,7 @@ func TestUpdater_cancel(t *testing.T) {
concurrentUpdater, err = New(ctx, repo)
require.NoError(t, err)
- require.NoError(t, concurrentUpdater.Delete(git.ReferenceName("refs/heads/master")))
+ require.NoError(t, concurrentUpdater.Delete(git.ReferenceName("refs/heads/main")))
require.NoError(t, concurrentUpdater.Commit())
}
@@ -251,14 +260,11 @@ func TestUpdater_closingStdinAbortsChanges(t *testing.T) {
ctx := testhelper.Context(t)
- _, repo, updater := setupUpdater(t, ctx)
-
- headCommit, err := repo.ReadCommit(ctx, "HEAD")
- require.NoError(t, err)
+ cfg, repo, repoPath, updater := setupUpdater(t, ctx)
- ref := git.ReferenceName("refs/heads/shouldnotexist")
+ commitID := gittest.WriteCommit(t, cfg, repoPath)
- require.NoError(t, updater.Create(ref, headCommit.Id))
+ require.NoError(t, updater.Create("refs/heads/main", commitID.String()))
// Note that we call `Wait()` on the command, not on the updater. This
// circumvents our usual semantics of sending "commit" and thus
@@ -269,7 +275,7 @@ func TestUpdater_closingStdinAbortsChanges(t *testing.T) {
// ... but as we now use explicit transactional behaviour, this is no
// longer the case.
- _, err = repo.ReadCommit(ctx, ref.Revision())
+ _, err := repo.ReadCommit(ctx, "refs/heads/main")
require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
}
@@ -278,22 +284,21 @@ func TestUpdater_capturesStderr(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, _, updater := setupUpdater(t, ctx)
+ cfg, _, _, updater := setupUpdater(t, ctx)
- ref := "refs/heads/a"
- newValue := strings.Repeat("1", 40)
- oldValue := git.ObjectHashSHA1.ZeroOID.String()
+ newValue := strings.Repeat("1", gittest.DefaultObjectHash.EncodedLen())
+ oldValue := gittest.DefaultObjectHash.ZeroOID.String()
- require.NoError(t, updater.Update(git.ReferenceName(ref), newValue, oldValue))
+ require.NoError(t, updater.Update("refs/heads/main", newValue, oldValue))
var expectedErr string
if gittest.GitSupportsStatusFlushing(t, ctx, cfg) {
- expectedErr = fmt.Sprintf("state update to \"commit\" failed: EOF, stderr: \"fatal: commit: cannot update ref '%s': "+
- "trying to write ref '%s' with nonexistent object %s\\n\"", ref, ref, newValue)
+ expectedErr = fmt.Sprintf("state update to \"commit\" failed: EOF, stderr: \"fatal: commit: cannot update ref '%[1]s': "+
+ "trying to write ref '%[1]s' with nonexistent object %[2]s\\n\"", "refs/heads/main", newValue)
} else {
expectedErr = fmt.Sprintf("git update-ref: exit status 128, stderr: "+
- "\"fatal: commit: cannot update ref '%s': "+
- "trying to write ref '%s' with nonexistent object %s\\n\"", ref, ref, newValue)
+ "\"fatal: commit: cannot update ref '%[1]s': "+
+ "trying to write ref '%[1]s' with nonexistent object %[2]s\\n\"", "refs/heads/main", newValue)
}
err := updater.Commit()