Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor editor upload, update and delete to use git plumbing and add LFS support #5702

Merged
merged 29 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
525f0b6
Use git plumbing for upload: #5621 repo_editor.go: UploadRepoFile
zeripath Dec 31, 2018
ba01dc0
Use git plumbing for upload: #5621 repo_editor.go: GetDiffPreview
zeripath Jan 2, 2019
ef4eea9
Use git plumbing for upload: #5621 repo_editor.go: DeleteRepoFile
zeripath Jan 2, 2019
3e46acd
Use git plumbing for upload: #5621 repo_editor.go: UploadRepoFiles
zeripath Jan 2, 2019
3203e98
Move branch checkout functions out of repo_editor.go as they are no l…
zeripath Jan 2, 2019
a5067f1
BUGFIX: The default permissions should be 100644
zeripath Jan 3, 2019
51c70aa
Standardise cleanUploadFilename to more closely match git
zeripath Jan 4, 2019
5b4d740
Redirect on bad paths
zeripath Jan 4, 2019
eabbdca
Refactor to move the uploading functions out to a module
zeripath Jan 10, 2019
4e6d433
Add LFS support
zeripath Jan 11, 2019
774d4c2
Update upload.go attribution header
zeripath Jan 13, 2019
78e27c2
Delete upload files after session committed
zeripath Jan 16, 2019
d0d28c9
Ensure that GIT_AUTHOR_NAME etc. are valid for git
zeripath Jan 20, 2019
d6ceb0c
Merge branch 'master' into make-upload-not-clone
zeripath Feb 6, 2019
2ba5664
Add in test cases per @lafriks comment
zeripath Feb 6, 2019
f2d5642
Merge branch 'master' into make-upload-not-clone
techknowlogick Feb 7, 2019
482cbfe
Add space between gitea and github imports
zeripath Feb 7, 2019
b346a29
more examples in TestCleanUploadName
zeripath Feb 7, 2019
12d320c
Merge branch 'master' into make-upload-not-clone
zeripath Feb 7, 2019
596b39d
Merge remote-tracking branch 'zeripath/make-upload-not-clone' into ma…
zeripath Feb 7, 2019
8a8b66b
fix formatting
zeripath Feb 7, 2019
c4e7804
Merge branch 'master' into make-upload-not-clone
zeripath Feb 7, 2019
ace5a66
Merge branch 'master' into make-upload-not-clone
zeripath Feb 8, 2019
f0d754b
Merge branch 'master' into make-upload-not-clone
zeripath Feb 9, 2019
d3dddff
Set the SSH_ORIGINAL_COMMAND to ensure hooks are run
zeripath Feb 9, 2019
30ccd16
Switch off SSH_ORIGINAL_COMMAND
zeripath Feb 9, 2019
65fbb98
Merge branch 'master' into make-upload-not-clone
zeripath Feb 10, 2019
9c3603b
Merge branch 'master' into make-upload-not-clone
zeripath Feb 12, 2019
fbe8f33
Merge branch 'master' into make-upload-not-clone
lunny Feb 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions models/lfs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package models

import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"

"code.gitea.io/gitea/modules/util"
)
Expand All @@ -16,6 +20,11 @@ type LFSMetaObject struct {
CreatedUnix util.TimeStamp `xorm:"created"`
}

// Pointer returns the string representation of an LFS pointer file
func (m *LFSMetaObject) Pointer() string {
return fmt.Sprintf("%s\n%s%s\nsize %d\n", LFSMetaFileIdentifier, LFSMetaFileOidPrefix, m.Oid, m.Size)
}

// LFSTokenResponse defines the JSON structure in which the JWT token is stored.
// This structure is fetched via SSH and passed by the Git LFS client to the server
// endpoint for authorization.
Expand Down Expand Up @@ -67,6 +76,16 @@ func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) {
return m, sess.Commit()
}

// GenerateLFSOid generates a Sha256Sum to represent an oid for arbitrary content
func GenerateLFSOid(content io.Reader) (string, error) {
h := sha256.New()
if _, err := io.Copy(h, content); err != nil {
return "", err
}
sum := h.Sum(nil)
return hex.EncodeToString(sum), nil
}

// GetLFSMetaObjectByOid selects a LFSMetaObject entry from database by its OID.
// It may return ErrLFSObjectNotExist or a database error. If the error is nil,
// the returned pointer is a valid LFSMetaObject.
Expand Down
40 changes: 40 additions & 0 deletions models/repo_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,46 @@ import (
"github.com/Unknwon/com"
)

// discardLocalRepoBranchChanges discards local commits/changes of
// given branch to make sure it is even to remote branch.
func discardLocalRepoBranchChanges(localPath, branch string) error {
if !com.IsExist(localPath) {
return nil
}
// No need to check if nothing in the repository.
if !git.IsBranchExist(localPath, branch) {
return nil
}

refName := "origin/" + branch
if err := git.ResetHEAD(localPath, true, refName); err != nil {
return fmt.Errorf("git reset --hard %s: %v", refName, err)
}
return nil
}

// DiscardLocalRepoBranchChanges discards the local repository branch changes
func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
}

// checkoutNewBranch checks out to a new branch from the a branch name.
func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
if err := git.Checkout(localPath, git.CheckoutOptions{
Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
Branch: newBranch,
OldBranch: oldBranch,
}); err != nil {
return fmt.Errorf("git checkout -b %s %s: %v", newBranch, oldBranch, err)
}
return nil
}

// CheckoutNewBranch checks out a new branch
func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
return checkoutNewBranch(repo.RepoPath(), repo.LocalCopyPath(), oldBranch, newBranch)
}

// Branch holds the branch information
type Branch struct {
Path string
Expand Down
Loading