mirror of https://github.com/go-gitea/gitea
Add support for sha256 repositories (#23894)
Currently only SHA1 repositories are supported by Gitea. This adds support for alternate SHA256 with the additional aim of easier support for additional hash types in the future. Fixes: #13794 Limited by: https://github.com/go-git/go-git/issues/899 Depend on: #28138 <img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447"> --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>pull/28856/head^2
parent
07ba4d9f87
commit
d68a613ba8
@ -0,0 +1,11 @@ |
||||
# type Repository struct { |
||||
# ID int64 `xorm:"pk autoincr"` |
||||
# } |
||||
- |
||||
id: 1 |
||||
- |
||||
id: 2 |
||||
- |
||||
id: 3 |
||||
- |
||||
id: 10 |
@ -0,0 +1,104 @@ |
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
package v1_22 //nolint
|
||||
|
||||
import ( |
||||
"errors" |
||||
"fmt" |
||||
|
||||
"code.gitea.io/gitea/modules/log" |
||||
"code.gitea.io/gitea/modules/setting" |
||||
|
||||
"xorm.io/xorm" |
||||
) |
||||
|
||||
func expandHashReferencesToSha256(x *xorm.Engine) error { |
||||
alteredTables := [][2]string{ |
||||
{"commit_status", "context_hash"}, |
||||
{"comment", "commit_sha"}, |
||||
{"pull_request", "merge_base"}, |
||||
{"pull_request", "merged_commit_id"}, |
||||
{"review", "commit_id"}, |
||||
{"review_state", "commit_sha"}, |
||||
{"repo_archiver", "commit_id"}, |
||||
{"release", "sha1"}, |
||||
{"repo_indexer_status", "commit_sha"}, |
||||
} |
||||
|
||||
db := x.NewSession() |
||||
defer db.Close() |
||||
|
||||
if err := db.Begin(); err != nil { |
||||
return err |
||||
} |
||||
|
||||
if !setting.Database.Type.IsSQLite3() { |
||||
if setting.Database.Type.IsMSSQL() { |
||||
// drop indexes that need to be re-created afterwards
|
||||
droppedIndexes := []string{ |
||||
"DROP INDEX commit_status.IDX_commit_status_context_hash", |
||||
"DROP INDEX review_state.UQE_review_state_pull_commit_user", |
||||
"DROP INDEX repo_archiver.UQE_repo_archiver_s", |
||||
} |
||||
for _, s := range droppedIndexes { |
||||
_, err := db.Exec(s) |
||||
if err != nil { |
||||
return errors.New(s + " " + err.Error()) |
||||
} |
||||
} |
||||
} |
||||
|
||||
for _, alts := range alteredTables { |
||||
var err error |
||||
if setting.Database.Type.IsMySQL() { |
||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` MODIFY COLUMN `%s` VARCHAR(64)", alts[0], alts[1])) |
||||
} else if setting.Database.Type.IsMSSQL() { |
||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` VARCHAR(64)", alts[0], alts[1])) |
||||
} else { |
||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` TYPE VARCHAR(64)", alts[0], alts[1])) |
||||
} |
||||
if err != nil { |
||||
return fmt.Errorf("alter column '%s' of table '%s' failed: %w", alts[1], alts[0], err) |
||||
} |
||||
} |
||||
|
||||
if setting.Database.Type.IsMSSQL() { |
||||
recreateIndexes := []string{ |
||||
"CREATE INDEX IDX_commit_status_context_hash ON commit_status(context_hash)", |
||||
"CREATE UNIQUE INDEX UQE_review_state_pull_commit_user ON review_state(user_id, pull_id, commit_sha)", |
||||
"CREATE UNIQUE INDEX UQE_repo_archiver_s ON repo_archiver(repo_id, type, commit_id)", |
||||
} |
||||
for _, s := range recreateIndexes { |
||||
_, err := db.Exec(s) |
||||
if err != nil { |
||||
return errors.New(s + " " + err.Error()) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
log.Debug("Updated database tables to hold SHA256 git hash references") |
||||
|
||||
return db.Commit() |
||||
} |
||||
|
||||
func addObjectFormatNameToRepository(x *xorm.Engine) error { |
||||
type Repository struct { |
||||
ObjectFormatName string `xorm:"VARCHAR(6) NOT NULL DEFAULT 'sha1'"` |
||||
} |
||||
|
||||
if err := x.Sync(new(Repository)); err != nil { |
||||
return err |
||||
} |
||||
|
||||
// Here to catch weird edge-cases where column constraints above are
|
||||
// not applied by the DB backend
|
||||
_, err := x.Exec("UPDATE repository set object_format_name = 'sha1' WHERE object_format_name = '' or object_format_name IS NULL") |
||||
return err |
||||
} |
||||
|
||||
func AdjustDBForSha256(x *xorm.Engine) error { |
||||
if err := expandHashReferencesToSha256(x); err != nil { |
||||
return err |
||||
} |
||||
return addObjectFormatNameToRepository(x) |
||||
} |
@ -0,0 +1,62 @@ |
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v1_22 //nolint
|
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"code.gitea.io/gitea/models/migrations/base" |
||||
|
||||
"github.com/stretchr/testify/assert" |
||||
"xorm.io/xorm" |
||||
) |
||||
|
||||
func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { |
||||
type Repository struct { // old struct
|
||||
ID int64 `xorm:"pk autoincr"` |
||||
} |
||||
|
||||
// Prepare and load the testing database
|
||||
return base.PrepareTestEnv(t, 0, new(Repository)) |
||||
} |
||||
|
||||
func Test_RepositoryFormat(t *testing.T) { |
||||
x, deferable := PrepareOldRepository(t) |
||||
defer deferable() |
||||
|
||||
type Repository struct { |
||||
ID int64 `xorm:"pk autoincr"` |
||||
ObjectFormatName string `xorg:"not null default('sha1')"` |
||||
} |
||||
|
||||
repo := new(Repository) |
||||
|
||||
// check we have some records to migrate
|
||||
count, err := x.Count(new(Repository)) |
||||
assert.NoError(t, err) |
||||
assert.EqualValues(t, 4, count) |
||||
|
||||
assert.NoError(t, AdjustDBForSha256(x)) |
||||
|
||||
repo.ID = 20 |
||||
repo.ObjectFormatName = "sha256" |
||||
_, err = x.Insert(repo) |
||||
assert.NoError(t, err) |
||||
|
||||
count, err = x.Count(new(Repository)) |
||||
assert.NoError(t, err) |
||||
assert.EqualValues(t, 5, count) |
||||
|
||||
repo = new(Repository) |
||||
ok, err := x.ID(2).Get(repo) |
||||
assert.NoError(t, err) |
||||
assert.EqualValues(t, true, ok) |
||||
assert.EqualValues(t, "sha1", repo.ObjectFormatName) |
||||
|
||||
repo = new(Repository) |
||||
ok, err = x.ID(20).Get(repo) |
||||
assert.NoError(t, err) |
||||
assert.EqualValues(t, true, ok) |
||||
assert.EqualValues(t, "sha256", repo.ObjectFormatName) |
||||
} |
@ -0,0 +1,144 @@ |
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package git |
||||
|
||||
import ( |
||||
"context" |
||||
"testing" |
||||
|
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
func TestReadingBlameOutputSha256(t *testing.T) { |
||||
ctx, cancel := context.WithCancel(context.Background()) |
||||
defer cancel() |
||||
|
||||
t.Run("Without .git-blame-ignore-revs", func(t *testing.T) { |
||||
repo, err := OpenRepository(ctx, "./tests/repos/repo5_pulls_sha256") |
||||
assert.NoError(t, err) |
||||
defer repo.Close() |
||||
|
||||
commit, err := repo.GetCommit("0b69b7bb649b5d46e14cabb6468685e5dd721290acc7ffe604d37cde57927345") |
||||
assert.NoError(t, err) |
||||
|
||||
parts := []*BlamePart{ |
||||
{ |
||||
Sha: "1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca", |
||||
Lines: []string{ |
||||
"# test_repo", |
||||
"Test repository for testing migration from github to gitea", |
||||
}, |
||||
}, |
||||
{ |
||||
Sha: "0b69b7bb649b5d46e14cabb6468685e5dd721290acc7ffe604d37cde57927345", |
||||
Lines: []string{"", "Do not make any changes to this repo it is used for unit testing"}, |
||||
PreviousSha: "1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca", |
||||
PreviousPath: "README.md", |
||||
}, |
||||
} |
||||
|
||||
for _, bypass := range []bool{false, true} { |
||||
blameReader, err := CreateBlameReader(ctx, Sha256ObjectFormat, "./tests/repos/repo5_pulls_sha256", commit, "README.md", bypass) |
||||
assert.NoError(t, err) |
||||
assert.NotNil(t, blameReader) |
||||
defer blameReader.Close() |
||||
|
||||
assert.False(t, blameReader.UsesIgnoreRevs()) |
||||
|
||||
for _, part := range parts { |
||||
actualPart, err := blameReader.NextPart() |
||||
assert.NoError(t, err) |
||||
assert.Equal(t, part, actualPart) |
||||
} |
||||
|
||||
// make sure all parts have been read
|
||||
actualPart, err := blameReader.NextPart() |
||||
assert.Nil(t, actualPart) |
||||
assert.NoError(t, err) |
||||
} |
||||
}) |
||||
|
||||
t.Run("With .git-blame-ignore-revs", func(t *testing.T) { |
||||
repo, err := OpenRepository(ctx, "./tests/repos/repo6_blame_sha256") |
||||
assert.NoError(t, err) |
||||
defer repo.Close() |
||||
|
||||
full := []*BlamePart{ |
||||
{ |
||||
Sha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", |
||||
Lines: []string{"line", "line"}, |
||||
}, |
||||
{ |
||||
Sha: "9347b0198cd1f25017579b79d0938fa89dba34ad2514f0dd92f6bc975ed1a2fe", |
||||
Lines: []string{"changed line"}, |
||||
PreviousSha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", |
||||
PreviousPath: "blame.txt", |
||||
}, |
||||
{ |
||||
Sha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", |
||||
Lines: []string{"line", "line", ""}, |
||||
}, |
||||
} |
||||
|
||||
cases := []struct { |
||||
CommitID string |
||||
UsesIgnoreRevs bool |
||||
Bypass bool |
||||
Parts []*BlamePart |
||||
}{ |
||||
{ |
||||
CommitID: "e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3", |
||||
UsesIgnoreRevs: true, |
||||
Bypass: false, |
||||
Parts: []*BlamePart{ |
||||
{ |
||||
Sha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", |
||||
Lines: []string{"line", "line", "changed line", "line", "line", ""}, |
||||
}, |
||||
}, |
||||
}, |
||||
{ |
||||
CommitID: "e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3", |
||||
UsesIgnoreRevs: false, |
||||
Bypass: true, |
||||
Parts: full, |
||||
}, |
||||
{ |
||||
CommitID: "9347b0198cd1f25017579b79d0938fa89dba34ad2514f0dd92f6bc975ed1a2fe", |
||||
UsesIgnoreRevs: false, |
||||
Bypass: false, |
||||
Parts: full, |
||||
}, |
||||
{ |
||||
CommitID: "9347b0198cd1f25017579b79d0938fa89dba34ad2514f0dd92f6bc975ed1a2fe", |
||||
UsesIgnoreRevs: false, |
||||
Bypass: false, |
||||
Parts: full, |
||||
}, |
||||
} |
||||
|
||||
for _, c := range cases { |
||||
commit, err := repo.GetCommit(c.CommitID) |
||||
assert.NoError(t, err) |
||||
|
||||
blameReader, err := CreateBlameReader(ctx, repo.objectFormat, "./tests/repos/repo6_blame_sha256", commit, "blame.txt", c.Bypass) |
||||
assert.NoError(t, err) |
||||
assert.NotNil(t, blameReader) |
||||
defer blameReader.Close() |
||||
|
||||
assert.Equal(t, c.UsesIgnoreRevs, blameReader.UsesIgnoreRevs()) |
||||
|
||||
for _, part := range c.Parts { |
||||
actualPart, err := blameReader.NextPart() |
||||
assert.NoError(t, err) |
||||
assert.Equal(t, part, actualPart) |
||||
} |
||||
|
||||
// make sure all parts have been read
|
||||
actualPart, err := blameReader.NextPart() |
||||
assert.Nil(t, actualPart) |
||||
assert.NoError(t, err) |
||||
} |
||||
}) |
||||
} |
@ -0,0 +1,195 @@ |
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build !gogit
|
||||
|
||||
package git |
||||
|
||||
import ( |
||||
"path/filepath" |
||||
"strings" |
||||
"testing" |
||||
|
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
func TestCommitsCountSha256(t *testing.T) { |
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") |
||||
|
||||
commitsCount, err := CommitsCount(DefaultContext, |
||||
CommitsCountOptions{ |
||||
RepoPath: bareRepo1Path, |
||||
Revision: []string{"f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc"}, |
||||
}) |
||||
|
||||
assert.NoError(t, err) |
||||
assert.Equal(t, int64(3), commitsCount) |
||||
} |
||||
|
||||
func TestCommitsCountWithoutBaseSha256(t *testing.T) { |
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") |
||||
|
||||
commitsCount, err := CommitsCount(DefaultContext, |
||||
CommitsCountOptions{ |
||||
RepoPath: bareRepo1Path, |
||||
Not: "main", |
||||
Revision: []string{"branch1"}, |
||||
}) |
||||
|
||||
assert.NoError(t, err) |
||||
assert.Equal(t, int64(2), commitsCount) |
||||
} |
||||
|
||||
func TestGetFullCommitIDSha256(t *testing.T) { |
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") |
||||
|
||||
id, err := GetFullCommitID(DefaultContext, bareRepo1Path, "f004f4") |
||||
assert.NoError(t, err) |
||||
assert.Equal(t, "f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc", id) |
||||
} |
||||
|
||||
func TestGetFullCommitIDErrorSha256(t *testing.T) { |
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") |
||||
|
||||
id, err := GetFullCommitID(DefaultContext, bareRepo1Path, "unknown") |
||||
assert.Empty(t, id) |
||||
if assert.Error(t, err) { |
||||
assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]") |
||||
} |
||||
} |
||||
|
||||
func TestCommitFromReaderSha256(t *testing.T) { |
||||
commitString := `9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 commit 1114 |
||||
tree e7f9e96dd79c09b078cac8b303a7d3b9d65ff9b734e86060a4d20409fd379f9e |
||||
parent 26e9ccc29fad747e9c5d9f4c9ddeb7eff61cc45ef6a8dc258cbeb181afc055e8 |
||||
author Adam Majer <amajer@suse.de> 1698676906 +0100 |
||||
committer Adam Majer <amajer@suse.de> 1698676906 +0100 |
||||
gpgsig-sha256 -----BEGIN PGP SIGNATURE----- |
||||
` + " " + ` |
||||
iQIrBAABCgAtFiEES+fB08xlgTrzSdQvhkUIsBsmec8FAmU/wKoPHGFtYWplckBz |
||||
dXNlLmRlAAoJEIZFCLAbJnnP4s4PQIJATa++WPzR6/H4etT7bsOGoMyguEJYyWOd |
||||
aTybplzT7QAL7h2to0QszGabtzMJPIA39xSFZNYNN30voK5YyyYibXluPKgjemfK |
||||
WNXwF+gkwgZI38gSvKf+vlqI+EYyIFe19wOhiju0m8SIlB5NEPiWHa17q2mqmqqx |
||||
1FWa2JdqLPYjAtSLFXeSZegrY5V1FxdemyMUONkg8YO9OSIMZiE0GsnnOXQ3xcT4 |
||||
JTCnmlUxIKw689UiEY80JopUIq+Wl7+qq9507IYYSUCyB6JazL42AKMzVCbD+qBP |
||||
oOzh/hafYgk9H9qCQXaLbmvs17zXRpicig1bAzqgAy1FDelvpERyRTydEajSLIG6 |
||||
U1cRCkgXCZ0NfsYNPPmBa8b3+rnstypXYTbyMwTln7FfUAaGo6o9JYiPMkzxlmsy |
||||
zfp/tcaY8+LlBL9aOJjtv+a0p+HrpCGd6CCa4ARfphTLq8QRSSh8uzlB9N+6HnRI |
||||
VAEUo6ecdDxSpyt2naeg9pKus/BRi7P6g4B1hkk/zZstUX/QP4IQuAJbXjkvsC+X |
||||
HKRr3NlRM/DygzTyj0gN74uoa0goCIbyAQhiT42nm0cuhM7uN/W0ayrlZjGF1cbR |
||||
8NCJUL2Nwj0ywKIavC99Ipkb8AsFwpVT6U6effs6 |
||||
=xybZ |
||||
-----END PGP SIGNATURE----- |
||||
|
||||
signed commit` |
||||
|
||||
sha := &Sha256Hash{ |
||||
0x94, 0x33, 0xb2, 0xa6, 0x2b, 0x96, 0x4c, 0x17, 0xa4, 0x48, 0x5a, 0xe1, 0x80, 0xf4, 0x5f, 0x59, |
||||
0x5d, 0x3e, 0x69, 0xd3, 0x1b, 0x78, 0x60, 0x87, 0x77, 0x5e, 0x28, 0xc6, 0xb6, 0x39, 0x9d, 0xf0, |
||||
} |
||||
gitRepo, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare_sha256")) |
||||
assert.NoError(t, err) |
||||
assert.NotNil(t, gitRepo) |
||||
defer gitRepo.Close() |
||||
|
||||
commitFromReader, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString)) |
||||
assert.NoError(t, err) |
||||
if !assert.NotNil(t, commitFromReader) { |
||||
return |
||||
} |
||||
assert.EqualValues(t, sha, commitFromReader.ID) |
||||
assert.EqualValues(t, `-----BEGIN PGP SIGNATURE----- |
||||
|
||||
iQIrBAABCgAtFiEES+fB08xlgTrzSdQvhkUIsBsmec8FAmU/wKoPHGFtYWplckBz |
||||
dXNlLmRlAAoJEIZFCLAbJnnP4s4PQIJATa++WPzR6/H4etT7bsOGoMyguEJYyWOd |
||||
aTybplzT7QAL7h2to0QszGabtzMJPIA39xSFZNYNN30voK5YyyYibXluPKgjemfK |
||||
WNXwF+gkwgZI38gSvKf+vlqI+EYyIFe19wOhiju0m8SIlB5NEPiWHa17q2mqmqqx |
||||
1FWa2JdqLPYjAtSLFXeSZegrY5V1FxdemyMUONkg8YO9OSIMZiE0GsnnOXQ3xcT4 |
||||
JTCnmlUxIKw689UiEY80JopUIq+Wl7+qq9507IYYSUCyB6JazL42AKMzVCbD+qBP |
||||
oOzh/hafYgk9H9qCQXaLbmvs17zXRpicig1bAzqgAy1FDelvpERyRTydEajSLIG6 |
||||
U1cRCkgXCZ0NfsYNPPmBa8b3+rnstypXYTbyMwTln7FfUAaGo6o9JYiPMkzxlmsy |
||||
zfp/tcaY8+LlBL9aOJjtv+a0p+HrpCGd6CCa4ARfphTLq8QRSSh8uzlB9N+6HnRI |
||||
VAEUo6ecdDxSpyt2naeg9pKus/BRi7P6g4B1hkk/zZstUX/QP4IQuAJbXjkvsC+X |
||||
HKRr3NlRM/DygzTyj0gN74uoa0goCIbyAQhiT42nm0cuhM7uN/W0ayrlZjGF1cbR |
||||
8NCJUL2Nwj0ywKIavC99Ipkb8AsFwpVT6U6effs6 |
||||
=xybZ |
||||
-----END PGP SIGNATURE----- |
||||
`, commitFromReader.Signature.Signature) |
||||
assert.EqualValues(t, `tree e7f9e96dd79c09b078cac8b303a7d3b9d65ff9b734e86060a4d20409fd379f9e |
||||
parent 26e9ccc29fad747e9c5d9f4c9ddeb7eff61cc45ef6a8dc258cbeb181afc055e8 |
||||
author Adam Majer <amajer@suse.de> 1698676906 +0100 |
||||
committer Adam Majer <amajer@suse.de> 1698676906 +0100 |
||||
|
||||
signed commit`, commitFromReader.Signature.Payload) |
||||
assert.EqualValues(t, "Adam Majer <amajer@suse.de>", commitFromReader.Author.String()) |
||||
|
||||
commitFromReader2, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString+"\n\n")) |
||||
assert.NoError(t, err) |
||||
commitFromReader.CommitMessage += "\n\n" |
||||
commitFromReader.Signature.Payload += "\n\n" |
||||
assert.EqualValues(t, commitFromReader, commitFromReader2) |
||||
} |
||||
|
||||
func TestHasPreviousCommitSha256(t *testing.T) { |
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") |
||||
|
||||
repo, err := openRepositoryWithDefaultContext(bareRepo1Path) |
||||
assert.NoError(t, err) |
||||
defer repo.Close() |
||||
|
||||
commit, err := repo.GetCommit("f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc") |
||||
assert.NoError(t, err) |
||||
|
||||
parentSHA := MustIDFromString("b0ec7af4547047f12d5093e37ef8f1b3b5415ed8ee17894d43a34d7d34212e9c") |
||||
notParentSHA := MustIDFromString("42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236") |
||||
assert.Equal(t, repo.objectFormat, parentSHA.Type()) |
||||
assert.Equal(t, repo.objectFormat.Name(), "sha256") |
||||
|
||||
haz, err := commit.HasPreviousCommit(parentSHA) |
||||
assert.NoError(t, err) |
||||
assert.True(t, haz) |
||||
|
||||
hazNot, err := commit.HasPreviousCommit(notParentSHA) |
||||
assert.NoError(t, err) |
||||
assert.False(t, hazNot) |
||||
|
||||
selfNot, err := commit.HasPreviousCommit(commit.ID) |
||||
assert.NoError(t, err) |
||||
assert.False(t, selfNot) |
||||
} |
||||
|
||||
func TestGetCommitFileStatusMergesSha256(t *testing.T) { |
||||
bareRepo1Path := filepath.Join(testReposDir, "repo6_merge_sha256") |
||||
|
||||
commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1") |
||||
assert.NoError(t, err) |
||||
|
||||
expected := CommitFileStatus{ |
||||
[]string{ |
||||
"add_file.txt", |
||||
}, |
||||
[]string{}, |
||||
[]string{ |
||||
"to_modify.txt", |
||||
}, |
||||
} |
||||
|
||||
assert.Equal(t, expected.Added, commitFileStatus.Added) |
||||
assert.Equal(t, expected.Removed, commitFileStatus.Removed) |
||||
assert.Equal(t, expected.Modified, commitFileStatus.Modified) |
||||
|
||||
expected = CommitFileStatus{ |
||||
[]string{}, |
||||
[]string{ |
||||
"to_remove.txt", |
||||
}, |
||||
[]string{}, |
||||
} |
||||
|
||||
commitFileStatus, err = GetCommitFileStatus(DefaultContext, bareRepo1Path, "da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172") |
||||
assert.NoError(t, err) |
||||
|
||||
assert.Equal(t, expected.Added, commitFileStatus.Added) |
||||
assert.Equal(t, expected.Removed, commitFileStatus.Removed) |
||||
assert.Equal(t, expected.Modified, commitFileStatus.Modified) |
||||
} |
@ -0,0 +1 @@ |
||||
ref: refs/heads/main |
@ -0,0 +1,6 @@ |
||||
[core] |
||||
repositoryformatversion = 1 |
||||
filemode = true |
||||
bare = true |
||||
[extensions] |
||||
objectformat = sha256 |
@ -0,0 +1 @@ |
||||
Unnamed repository; edit this file 'description' to name the repository. |
@ -0,0 +1,6 @@ |
||||
# git ls-files --others --exclude-from=.git/info/exclude |
||||
# Lines that start with '#' are comments. |
||||
# For a project mostly in C, the following would be a good set of |
||||
# exclude patterns (uncomment them if you want to use them): |
||||
# *.[oa] |
||||
# *~ |
@ -0,0 +1,7 @@ |
||||
42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236 refs/heads/branch1 |
||||
5bc2249e32e0ba40a08879fba2bd4e97a13cb345831549f4bc5649525da8f6cc refs/heads/branch2 |
||||
9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 refs/heads/main |
||||
29a82d4fc02e19190fb489cc90d5730ed91970b49f4e39acda2798b3dd4f814e refs/tags/signed-tag |
||||
9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 refs/tags/signed-tag^{} |
||||
171822a62559f3aa28a00aa3785dbe915d6a8eb02712682740db44fc8bd2187a refs/tags/test |
||||
6aae864a3d1d0d6a5be0cc64028c1e7021e2632b031fd8eb82afc5a283d1c3d1 refs/tags/test^{} |
Binary file not shown.
@ -0,0 +1,2 @@ |
||||
P pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.pack |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,8 @@ |
||||
# pack-refs with: peeled fully-peeled sorted |
||||
42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236 refs/heads/branch1 |
||||
5bc2249e32e0ba40a08879fba2bd4e97a13cb345831549f4bc5649525da8f6cc refs/heads/branch2 |
||||
9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 refs/heads/main |
||||
29a82d4fc02e19190fb489cc90d5730ed91970b49f4e39acda2798b3dd4f814e refs/tags/signed-tag |
||||
^9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 |
||||
171822a62559f3aa28a00aa3785dbe915d6a8eb02712682740db44fc8bd2187a refs/tags/test |
||||
^6aae864a3d1d0d6a5be0cc64028c1e7021e2632b031fd8eb82afc5a283d1c3d1 |
@ -0,0 +1 @@ |
||||
9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 |
@ -0,0 +1 @@ |
||||
ref: refs/heads/main |
@ -0,0 +1,6 @@ |
||||
[core] |
||||
repositoryformatversion = 1 |
||||
filemode = true |
||||
bare = true |
||||
[extensions] |
||||
objectformat = sha256 |
@ -0,0 +1 @@ |
||||
Unnamed repository; edit this file 'description' to name the repository. |
@ -0,0 +1,4 @@ |
||||
35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b refs/heads/main |
||||
35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b refs/heads/main-clone |
||||
7f50a4906503378b0bbb7d61bd2ca8d8d8ff4f7a2474980f99402d742ccc9665 refs/heads/test-patch-1 |
||||
1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca refs/tags/v0.9.99 |
Binary file not shown.
@ -0,0 +1,2 @@ |
||||
P pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.pack |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@ |
||||
# pack-refs with: peeled fully-peeled sorted |
||||
35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b refs/heads/main |
||||
35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b refs/heads/main-clone |
||||
7f50a4906503378b0bbb7d61bd2ca8d8d8ff4f7a2474980f99402d742ccc9665 refs/heads/test-patch-1 |
||||
1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca refs/tags/v0.9.99 |
@ -0,0 +1 @@ |
||||
35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b |
@ -0,0 +1 @@ |
||||
ref: refs/heads/main |
@ -0,0 +1,6 @@ |
||||
[core] |
||||
repositoryformatversion = 1 |
||||
filemode = true |
||||
bare = true |
||||
[extensions] |
||||
objectformat = sha256 |
@ -0,0 +1 @@ |
||||
Unnamed repository; edit this file 'description' to name the repository. |
@ -0,0 +1,6 @@ |
||||
# git ls-files --others --exclude-from=.git/info/exclude |
||||
# Lines that start with '#' are comments. |
||||
# For a project mostly in C, the following would be a good set of |
||||
# exclude patterns (uncomment them if you want to use them): |
||||
# *.[oa] |
||||
# *~ |
@ -0,0 +1 @@ |
||||
e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3 refs/heads/main |
Binary file not shown.
@ -0,0 +1,2 @@ |
||||
P pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.pack |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,2 @@ |
||||
# pack-refs with: peeled fully-peeled sorted |
||||
e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3 refs/heads/main |
@ -0,0 +1 @@ |
||||
e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3 |
@ -0,0 +1 @@ |
||||
ref: refs/heads/main |
@ -0,0 +1,6 @@ |
||||
[core] |
||||
repositoryformatversion = 1 |
||||
filemode = true |
||||
bare = true |
||||
[extensions] |
||||
objectformat = sha256 |
@ -0,0 +1 @@ |
||||
Unnamed repository; edit this file 'description' to name the repository. |
@ -0,0 +1,6 @@ |
||||
# git ls-files --others --exclude-from=.git/info/exclude |
||||
# Lines that start with '#' are comments. |
||||
# For a project mostly in C, the following would be a good set of |
||||
# exclude patterns (uncomment them if you want to use them): |
||||
# *.[oa] |
||||
# *~ |
@ -0,0 +1,4 @@ |
||||
d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1 refs/heads/main |
||||
b45258e9823233edea2d40d183742f29630e1e69300479fb4a55eabfe9b1d8bf refs/heads/merge/add_file |
||||
ff2b996e2fa366146300e4c9e51ccb6818147b360e46fa1437334f4a690955ce refs/heads/merge/modify_file |
||||
da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172 refs/heads/merge/remove_file |
Binary file not shown.
@ -0,0 +1,3 @@ |
||||
P pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.pack |
||||
P pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.pack |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@ |
||||
# pack-refs with: peeled fully-peeled sorted |
||||
d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1 refs/heads/main |
||||
b45258e9823233edea2d40d183742f29630e1e69300479fb4a55eabfe9b1d8bf refs/heads/merge/add_file |
||||
ff2b996e2fa366146300e4c9e51ccb6818147b360e46fa1437334f4a690955ce refs/heads/merge/modify_file |
||||
da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172 refs/heads/merge/remove_file |
@ -0,0 +1 @@ |
||||
d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1 |
Loading…
Reference in new issue