Skip to content

POC: Rework update file via git fast-import #34293

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions modules/git/attribute/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (attrs *Attributes) GetLinguistLanguage() optional.Option[string] {
return attrs.Get(LinguistLanguage).ToString()
}

func (attrs *Attributes) MatchLFS() bool {
return attrs.Get(Filter).ToString().Value() == "lfs"
}

func (attrs *Attributes) GetGitlabLanguage() optional.Option[string] {
attrStr := attrs.Get(GitlabLanguage).ToString()
if attrStr.Has() {
Expand Down
96 changes: 32 additions & 64 deletions routers/api/v1/repo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,26 +485,18 @@ func ChangeFiles(ctx *context.APIContext) {
Message: apiOpts.Message,
OldBranch: apiOpts.BranchName,
NewBranch: apiOpts.NewBranchName,
Committer: &files_service.IdentityOptions{
GitUserName: apiOpts.Committer.Name,
GitUserEmail: apiOpts.Committer.Email,
Committer: &git.Signature{
Name: apiOpts.Committer.Name,
Email: apiOpts.Committer.Email,
When: apiOpts.Dates.Committer,
},
Author: &files_service.IdentityOptions{
GitUserName: apiOpts.Author.Name,
GitUserEmail: apiOpts.Author.Email,
},
Dates: &files_service.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
Author: &git.Signature{
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
When: apiOpts.Dates.Author,
},
Signoff: apiOpts.Signoff,
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}

if opts.Message == "" {
opts.Message = changeFilesCommitMessage(ctx, files)
Expand Down Expand Up @@ -582,26 +574,18 @@ func CreateFile(ctx *context.APIContext) {
Message: apiOpts.Message,
OldBranch: apiOpts.BranchName,
NewBranch: apiOpts.NewBranchName,
Committer: &files_service.IdentityOptions{
GitUserName: apiOpts.Committer.Name,
GitUserEmail: apiOpts.Committer.Email,
Committer: &git.Signature{
Name: apiOpts.Committer.Name,
Email: apiOpts.Committer.Email,
When: apiOpts.Dates.Committer,
},
Author: &files_service.IdentityOptions{
GitUserName: apiOpts.Author.Name,
GitUserEmail: apiOpts.Author.Email,
},
Dates: &files_service.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
Author: &git.Signature{
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
When: apiOpts.Dates.Author,
},
Signoff: apiOpts.Signoff,
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}

if opts.Message == "" {
opts.Message = changeFilesCommitMessage(ctx, opts.Files)
Expand Down Expand Up @@ -685,26 +669,18 @@ func UpdateFile(ctx *context.APIContext) {
Message: apiOpts.Message,
OldBranch: apiOpts.BranchName,
NewBranch: apiOpts.NewBranchName,
Committer: &files_service.IdentityOptions{
GitUserName: apiOpts.Committer.Name,
GitUserEmail: apiOpts.Committer.Email,
Committer: &git.Signature{
Name: apiOpts.Committer.Name,
Email: apiOpts.Committer.Email,
When: apiOpts.Dates.Committer,
},
Author: &files_service.IdentityOptions{
GitUserName: apiOpts.Author.Name,
GitUserEmail: apiOpts.Author.Email,
},
Dates: &files_service.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
Author: &git.Signature{
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
When: apiOpts.Dates.Author,
},
Signoff: apiOpts.Signoff,
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}

if opts.Message == "" {
opts.Message = changeFilesCommitMessage(ctx, opts.Files)
Expand Down Expand Up @@ -844,26 +820,18 @@ func DeleteFile(ctx *context.APIContext) {
Message: apiOpts.Message,
OldBranch: apiOpts.BranchName,
NewBranch: apiOpts.NewBranchName,
Committer: &files_service.IdentityOptions{
GitUserName: apiOpts.Committer.Name,
GitUserEmail: apiOpts.Committer.Email,
Committer: &git.Signature{
Name: apiOpts.Committer.Name,
Email: apiOpts.Committer.Email,
When: apiOpts.Dates.Committer,
},
Author: &files_service.IdentityOptions{
GitUserName: apiOpts.Author.Name,
GitUserEmail: apiOpts.Author.Email,
},
Dates: &files_service.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
Author: &git.Signature{
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
When: apiOpts.Dates.Author,
},
Signoff: apiOpts.Signoff,
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}

if opts.Message == "" {
opts.Message = changeFilesCommitMessage(ctx, opts.Files)
Expand Down
26 changes: 19 additions & 7 deletions routers/web/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,15 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
ContentReader: strings.NewReader(strings.ReplaceAll(form.Content, "\r", "")),
},
},
Signoff: form.Signoff,
Author: gitCommitter,
Committer: gitCommitter,
Signoff: form.Signoff,
Author: &git.Signature{
Name: gitCommitter.GitUserName,
Email: gitCommitter.GitUserEmail,
},
Committer: &git.Signature{
Name: gitCommitter.GitUserName,
Email: gitCommitter.GitUserEmail,
},
}); err != nil {
// This is where we handle all the errors thrown by files_service.ChangeRepoFiles
if git.IsErrNotExist(err) {
Expand Down Expand Up @@ -512,10 +518,16 @@ func DeleteFilePost(ctx *context.Context) {
TreePath: ctx.Repo.TreePath,
},
},
Message: message,
Signoff: form.Signoff,
Author: gitCommitter,
Committer: gitCommitter,
Message: message,
Signoff: form.Signoff,
Author: &git.Signature{
Name: gitCommitter.GitUserName,
Email: gitCommitter.GitUserEmail,
},
Committer: &git.Signature{
Name: gitCommitter.GitUserName,
Email: gitCommitter.GitUserEmail,
},
}); err != nil {
// This is where we handle all the errors thrown by repofiles.DeleteRepoFile
if git.IsErrNotExist(err) || files_service.IsErrRepoFileDoesNotExist(err) {
Expand Down
4 changes: 0 additions & 4 deletions services/repository/files/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestMain(m *testing.M) {
unittest.MainTest(m)
}

func getExpectedReadmeContentsResponse() *api.ContentsResponse {
treePath := "README.md"
sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
Expand Down
Loading
Loading