mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-06 01:09:33 +00:00
296814e887
* Use git plumbing for upload: #5621 repo_editor.go: UploadRepoFile
* Use git plumbing for upload: #5621 repo_editor.go: GetDiffPreview
* Use git plumbing for upload: #5621 repo_editor.go: DeleteRepoFile
* Use git plumbing for upload: #5621 repo_editor.go: UploadRepoFiles
* Move branch checkout functions out of repo_editor.go as they are no longer used there
* BUGFIX: The default permissions should be 100644
This is a change from the previous code but is more in keeping
with the default behaviour of git.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Standardise cleanUploadFilename to more closely match git
See verify_path in: 7f4e641693/read-cache.c (L951)
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Redirect on bad paths
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Refactor to move the uploading functions out to a module
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add LFS support
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Update upload.go attribution header
Upload.go is essentially the remnants of repo_editor.go. The remaining code is essentially unchanged from the Gogs code, hence the Gogs attribution.
* Delete upload files after session committed
* Ensure that GIT_AUTHOR_NAME etc. are valid for git
see #5774
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add in test cases per @lafriks comment
* Add space between gitea and github imports
Signed-off-by: Andrew Thornton <art27@cantab.net>
* more examples in TestCleanUploadName
Signed-off-by: Andrew Thornton <art27@cantab.net>
* fix formatting
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Set the SSH_ORIGINAL_COMMAND to ensure hooks are run
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Switch off SSH_ORIGINAL_COMMAND
Signed-off-by: Andrew Thornton <art27@cantab.net>
38 lines
945 B
Go
38 lines
945 B
Go
// Copyright 2019 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 uploader
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
)
|
|
|
|
// GetDiffPreview produces and returns diff result of a file which is not yet committed.
|
|
func GetDiffPreview(repo *models.Repository, branch, treePath, content string) (*models.Diff, error) {
|
|
t, err := NewTemporaryUploadRepository(repo)
|
|
defer t.Close()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := t.Clone(branch); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := t.SetDefaultIndex(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Add the object to the database
|
|
objectHash, err := t.HashObject(strings.NewReader(content))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Add the object to the index
|
|
if err := t.AddObjectToIndex("100644", objectHash, treePath); err != nil {
|
|
return nil, err
|
|
}
|
|
return t.DiffIndex()
|
|
}
|