-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LFS Migration and Mirror (#14726)
* Implemented LFS client. * Implemented scanning for pointer files. * Implemented downloading of lfs files. * Moved model-dependent code into services. * Removed models dependency. Added TryReadPointerFromBuffer. * Migrated code from service to module. * Centralised storage creation. * Removed dependency from models. * Moved ContentStore into modules. * Share structs between server and client. * Moved method to services. * Implemented lfs download on clone. * Implemented LFS sync on clone and mirror update. * Added form fields. * Updated templates. * Fixed condition. * Use alternate endpoint. * Added missing methods. * Fixed typo and make linter happy. * Detached pointer parser from gogit dependency. * Fixed TestGetLFSRange test. * Added context to support cancellation. * Use ReadFull to probably read more data. * Removed duplicated code from models. * Moved scan implementation into pointer_scanner_nogogit. * Changed method name. * Added comments. * Added more/specific log/error messages. * Embedded lfs.Pointer into models.LFSMetaObject. * Moved code from models to module. * Moved code from models to module. * Moved code from models to module. * Reduced pointer usage. * Embedded type. * Use promoted fields. * Fixed unexpected eof. * Added unit tests. * Implemented migration of local file paths. * Show an error on invalid LFS endpoints. * Hide settings if not used. * Added LFS info to mirror struct. * Fixed comment. * Check LFS endpoint. * Manage LFS settings from mirror page. * Fixed selector. * Adjusted selector. * Added more tests. * Added local filesystem migration test. * Fixed typo. * Reset settings. * Added special windows path handling. * Added unit test for HTTPClient. * Added unit test for BasicTransferAdapter. * Moved into util package. * Test if LFS endpoint is allowed. * Added support for git:// * Just use a static placeholder as the displayed url may be invalid. * Reverted to original code. * Added "Advanced Settings". * Updated wording. * Added discovery info link. * Implemented suggestion. * Fixed missing format parameter. * Added Pointer.IsValid(). * Always remove model on error. * Added suggestions. * Use channel instead of array. * Update routers/repo/migrate.go * fmt Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: zeripath <[email protected]>
- Loading branch information
Showing
75 changed files
with
2,158 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"net/http" | ||
"path" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/lfs" | ||
"code.gitea.io/gitea/modules/setting" | ||
api "code.gitea.io/gitea/modules/structs" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAPIRepoLFSMigrateLocal(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
oldImportLocalPaths := setting.ImportLocalPaths | ||
oldAllowLocalNetworks := setting.Migrations.AllowLocalNetworks | ||
setting.ImportLocalPaths = true | ||
setting.Migrations.AllowLocalNetworks = true | ||
|
||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) | ||
session := loginUser(t, user.Name) | ||
token := getTokenForLoggedInUser(t, session) | ||
|
||
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+token, &api.MigrateRepoOptions{ | ||
CloneAddr: path.Join(setting.RepoRootPath, "migration/lfs-test.git"), | ||
RepoOwnerID: user.ID, | ||
RepoName: "lfs-test-local", | ||
LFS: true, | ||
}) | ||
resp := MakeRequest(t, req, NoExpectedStatus) | ||
assert.EqualValues(t, http.StatusCreated, resp.Code) | ||
|
||
store := lfs.NewContentStore() | ||
ok, _ := store.Verify(lfs.Pointer{Oid: "fb8f7d8435968c4f82a726a92395be4d16f2f63116caf36c8ad35c60831ab041", Size: 6}) | ||
assert.True(t, ok) | ||
ok, _ = store.Verify(lfs.Pointer{Oid: "d6f175817f886ec6fbbc1515326465fa96c3bfd54a4ea06cfd6dbbd8340e0152", Size: 6}) | ||
assert.True(t, ok) | ||
|
||
setting.ImportLocalPaths = oldImportLocalPaths | ||
setting.Migrations.AllowLocalNetworks = oldAllowLocalNetworks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/migration/lfs-test.git/HEAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ref: refs/heads/master |
7 changes: 7 additions & 0 deletions
7
integrations/gitea-repositories-meta/migration/lfs-test.git/config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[core] | ||
bare = false | ||
repositoryformatversion = 0 | ||
filemode = false | ||
symlinks = false | ||
ignorecase = true | ||
logallrefupdates = true |
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/migration/lfs-test.git/description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unnamed repository; edit this file 'description' to name the repository. |
3 changes: 3 additions & 0 deletions
3
integrations/gitea-repositories-meta/migration/lfs-test.git/hooks/post-checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-checkout.\n"; exit 2; } | ||
git lfs post-checkout "$@" |
3 changes: 3 additions & 0 deletions
3
integrations/gitea-repositories-meta/migration/lfs-test.git/hooks/post-commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n"; exit 2; } | ||
git lfs post-commit "$@" |
3 changes: 3 additions & 0 deletions
3
integrations/gitea-repositories-meta/migration/lfs-test.git/hooks/post-merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-merge.\n"; exit 2; } | ||
git lfs post-merge "$@" |
3 changes: 3 additions & 0 deletions
3
integrations/gitea-repositories-meta/migration/lfs-test.git/hooks/pre-push
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; } | ||
git lfs pre-push "$@" |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...st.git/lfs/objects/d6/f1/d6f175817f886ec6fbbc1515326465fa96c3bfd54a4ea06cfd6dbbd8340e0152
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy2 |
1 change: 1 addition & 0 deletions
1
...st.git/lfs/objects/fb/8f/fb8f7d8435968c4f82a726a92395be4d16f2f63116caf36c8ad35c60831ab041
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy1 |
Binary file added
BIN
+128 Bytes
...epositories-meta/migration/lfs-test.git/objects/54/6244003622c64b2fc3c2cd544d7a29882c8383
Binary file not shown.
Binary file added
BIN
+51 Bytes
...epositories-meta/migration/lfs-test.git/objects/6a/6ccf5d874fec134ee712572cc03a0f2dd7afec
Binary file not shown.
Binary file added
BIN
+121 Bytes
...epositories-meta/migration/lfs-test.git/objects/a6/7134b8484c2abe9fa954e1fd83b39b271383ed
Binary file not shown.
Binary file added
BIN
+122 Bytes
...epositories-meta/migration/lfs-test.git/objects/b7/01ed6ffe410f0c3ac204b929ea47cfec6cef54
Binary file not shown.
Binary file added
BIN
+120 Bytes
...epositories-meta/migration/lfs-test.git/objects/f2/07b74f55cd7f9e800b7550d587cbc488f6eaf1
Binary file not shown.
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/migration/lfs-test.git/refs/heads/master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
546244003622c64b2fc3c2cd544d7a29882c8383 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/lfs" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func str2url(raw string) *url.URL { | ||
u, _ := url.Parse(raw) | ||
return u | ||
} | ||
|
||
func TestDetermineLocalEndpoint(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
root, _ := ioutil.TempDir("", "lfs_test") | ||
defer os.RemoveAll(root) | ||
|
||
rootdotgit, _ := ioutil.TempDir("", "lfs_test") | ||
defer os.RemoveAll(rootdotgit) | ||
os.Mkdir(filepath.Join(rootdotgit, ".git"), 0700) | ||
|
||
lfsroot, _ := ioutil.TempDir("", "lfs_test") | ||
defer os.RemoveAll(lfsroot) | ||
|
||
// Test cases | ||
var cases = []struct { | ||
cloneurl string | ||
lfsurl string | ||
expected *url.URL | ||
}{ | ||
// case 0 | ||
{ | ||
cloneurl: root, | ||
lfsurl: "", | ||
expected: str2url(fmt.Sprintf("file://%s", root)), | ||
}, | ||
// case 1 | ||
{ | ||
cloneurl: root, | ||
lfsurl: lfsroot, | ||
expected: str2url(fmt.Sprintf("file://%s", lfsroot)), | ||
}, | ||
// case 2 | ||
{ | ||
cloneurl: "https://git.com/repo.git", | ||
lfsurl: lfsroot, | ||
expected: str2url(fmt.Sprintf("file://%s", lfsroot)), | ||
}, | ||
// case 3 | ||
{ | ||
cloneurl: rootdotgit, | ||
lfsurl: "", | ||
expected: str2url(fmt.Sprintf("file://%s", filepath.Join(rootdotgit, ".git"))), | ||
}, | ||
// case 4 | ||
{ | ||
cloneurl: "", | ||
lfsurl: rootdotgit, | ||
expected: str2url(fmt.Sprintf("file://%s", filepath.Join(rootdotgit, ".git"))), | ||
}, | ||
// case 5 | ||
{ | ||
cloneurl: rootdotgit, | ||
lfsurl: rootdotgit, | ||
expected: str2url(fmt.Sprintf("file://%s", filepath.Join(rootdotgit, ".git"))), | ||
}, | ||
// case 6 | ||
{ | ||
cloneurl: fmt.Sprintf("file://%s", root), | ||
lfsurl: "", | ||
expected: str2url(fmt.Sprintf("file://%s", root)), | ||
}, | ||
// case 7 | ||
{ | ||
cloneurl: fmt.Sprintf("file://%s", root), | ||
lfsurl: fmt.Sprintf("file://%s", lfsroot), | ||
expected: str2url(fmt.Sprintf("file://%s", lfsroot)), | ||
}, | ||
// case 8 | ||
{ | ||
cloneurl: root, | ||
lfsurl: fmt.Sprintf("file://%s", lfsroot), | ||
expected: str2url(fmt.Sprintf("file://%s", lfsroot)), | ||
}, | ||
// case 9 | ||
{ | ||
cloneurl: "", | ||
lfsurl: "/does/not/exist", | ||
expected: nil, | ||
}, | ||
// case 10 | ||
{ | ||
cloneurl: "", | ||
lfsurl: "file:///does/not/exist", | ||
expected: str2url("file:///does/not/exist"), | ||
}, | ||
} | ||
|
||
for n, c := range cases { | ||
ep := lfs.DetermineEndpoint(c.cloneurl, c.lfsurl) | ||
|
||
assert.Equal(t, c.expected, ep, "case %d: error should match", n) | ||
} | ||
} |
Oops, something went wrong.