diff options
author | James Fargher <jfargher@gitlab.com> | 2021-11-30 01:22:32 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2021-12-02 23:44:13 +0300 |
commit | 2f4f5196b675e3a0d0c75880a856ebf8f64d9a5e (patch) | |
tree | 3f48a5b1d9b06aa245fecbcab841ce290739de96 | |
parent | c0b167298c043e4826cb1ae823c62f85e4920f3b (diff) |
backup: Set HEAD from bundle filesupdate-head-14-5
Previously backup relied on git-clone setting HEAD from bundle files but
now that we apply a series of bundles, the bundles are applied using
git-fetch instead. This means we need to apply our own HEAD setting
logic based off of the bundle.
ChecksumTestRepo was incorrectly calculating repository checksums
without HEAD.
Changelog: fixed
-rw-r--r-- | internal/backup/backup.go | 2 | ||||
-rw-r--r-- | internal/backup/backup_test.go | 4 | ||||
-rw-r--r-- | internal/git/gittest/repo.go | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go index b26e47466..f596b216d 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -395,7 +395,7 @@ func (mgr *Manager) restoreBundle(ctx context.Context, path string, server stora if err != nil { return fmt.Errorf("restore bundle: %q: %w", path, err) } - request := &gitalypb.FetchBundleRequest{Repository: repo} + request := &gitalypb.FetchBundleRequest{Repository: repo, UpdateHead: true} bundle := streamio.NewWriter(func(p []byte) error { request.Data = p if err := stream.Send(request); err != nil { diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index b7226ff93..0e3c36ecf 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -479,8 +479,10 @@ func testManagerRestore(t *testing.T, cfg config.Cfg, gitalyAddr string) { gittest.WithBranch("other"), gittest.WithParents(root), ) + gittest.Exec(t, cfg, "-C", expectedRepoPath, "symbolic-ref", "HEAD", "refs/heads/master") bundlePath1 := filepath.Join(backupPath, "001.bundle") gittest.Exec(t, cfg, "-C", expectedRepoPath, "bundle", "create", bundlePath1, + "HEAD", "refs/heads/master", "refs/heads/other", ) @@ -491,6 +493,7 @@ func testManagerRestore(t *testing.T, cfg config.Cfg, gitalyAddr string) { ) bundlePath2 := filepath.Join(backupPath, "002.bundle") gittest.Exec(t, cfg, "-C", expectedRepoPath, "bundle", "create", bundlePath2, + "HEAD", "^"+master1.String(), "^"+other.String(), "refs/heads/master", @@ -498,6 +501,7 @@ func testManagerRestore(t *testing.T, cfg config.Cfg, gitalyAddr string) { ) checksum := new(git.Checksum) + checksum.Add(git.NewReference("HEAD", master2.String())) checksum.Add(git.NewReference("refs/heads/master", master2.String())) checksum.Add(git.NewReference("refs/heads/other", other.String())) diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go index 1f060b4ca..26058d503 100644 --- a/internal/git/gittest/repo.go +++ b/internal/git/gittest/repo.go @@ -173,7 +173,7 @@ func BundleTestRepo(t testing.TB, cfg config.Cfg, sourceRepo, bundlePath string, func ChecksumTestRepo(t testing.TB, cfg config.Cfg, sourceRepo string) *git.Checksum { var checksum git.Checksum repoPath := testRepositoryPath(t, sourceRepo) - lines := bytes.Split(Exec(t, cfg, "-C", repoPath, "show-ref"), []byte("\n")) + lines := bytes.Split(Exec(t, cfg, "-C", repoPath, "show-ref", "--head"), []byte("\n")) for _, line := range lines { checksum.AddBytes(line) } |