-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add apply-patch, basic revert and cherry-pick functionality #17902
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
Merged
Merged
Changes from 32 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
13ba415
Add apply-patch button
zeripath d477e5a
placate lint
zeripath c3326b2
update copyright years
zeripath f2c01fd
Merge branch 'main' into apply-patch
zeripath d4a4f1f
Update templates/repo/editor/patch.tmpl
zeripath 8d9a6df
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath d0fc943
Merge remote-tracking branch 'zeripath/apply-patch' into apply-patch
zeripath ea9f569
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath c767f86
handle conflict
zeripath 6ac0064
Add basic cherry-pick and revert functionality
zeripath 8b3cdba
placate lint
zeripath 2527d2d
slight further improvement
zeripath 427e99c
placate lint
zeripath 20b6b1e
Use git read-tree -m for better cherry-picking and reversion first
zeripath b23c35b
Improve TestPatch to use git read-tree -m
zeripath 2f65bf9
Merge branch 'main' into update-TestPatch-to-use-read-tree
zeripath 46bcf3e
Implement the git-merge-one-file algorithm
zeripath cb4e9e1
and handle empty patches too
zeripath 507ede4
placate lint
zeripath 7a523dd
use errConflict instead callback
zeripath 0a38bd1
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath 8193743
Merge remote-tracking branch 'origin/main' into update-TestPatch-to-u…
zeripath e02708e
Merge branch 'update-TestPatch-to-use-read-tree' into apply-patch
zeripath 92de7bf
use the new updated merging from TestPatch
zeripath 490ac9a
move revert and cherry-pick to drop down for operations and add creat…
zeripath 561160f
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath 6a47494
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath 20c6e69
Split off other actions button
zeripath d707b88
remove browse-button css
zeripath 406f525
as per review
zeripath 1ac56a6
as per noerw
zeripath 7244187
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath 4a4caf2
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath 5049cc9
Fix bug
zeripath d3bbf2e
Merge branch 'main' into apply-patch
zeripath b43ac20
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath d371168
Merge branch 'main' into apply-patch
zeripath 7170909
Merge remote-tracking branch 'origin/main' into apply-patch
zeripath 7cf8382
fix linting and conflicts from previous prs
zeripath bed30e6
Merge branch 'main' into apply-patch
6543 6ec8527
Merge branch 'main' into apply-patch
6543 046da34
use git.NewCommandContext
6543 ac0be2d
cmd.RunWithContext do use processManager ...
6543 2ca39bb
use RunWithContext
6543 6ca8f13
Merge branch 'main' into apply-patch
zeripath 9557783
Merge branch 'main' into apply-patch
6543 31fddcb
Merge branch 'master' into apply-patch
6543 095823d
adapt refactor
6543 6494e11
pass ctx down
6543 6fbc6e1
cherrypick use normal ctx
6543 1f6e6e9
use attr
zeripath 683822b
Merge branch 'main' into apply-patch
zeripath 63c5656
as per reviews
zeripath f20e9d4
Merge branch 'main' into apply-patch
6543 ff58993
Merge branch 'main' into apply-patch
zeripath c7c3c63
Merge branch 'main' into apply-patch
zeripath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,106 @@ | ||
// 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 repo | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/git" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/web" | ||
"code.gitea.io/gitea/services/repository/files" | ||
) | ||
|
||
// ApplyDiffPatch handles API call for applying a patch | ||
func ApplyDiffPatch(ctx *context.APIContext) { | ||
// swagger:operation POST /repos/{owner}/{repo}/diffpatch repository repoApplyDiffPatch | ||
// --- | ||
// summary: Apply diff patch to repository | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: owner | ||
// in: path | ||
// description: owner of the repo | ||
// type: string | ||
// required: true | ||
// - name: repo | ||
// in: path | ||
// description: name of the repo | ||
// type: string | ||
// required: true | ||
// - name: body | ||
// in: body | ||
// required: true | ||
// schema: | ||
// "$ref": "#/definitions/UpdateFileOptions" | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/FileResponse" | ||
apiOpts := web.GetForm(ctx).(*api.ApplyDiffPatchFileOptions) | ||
|
||
opts := &files.ApplyDiffPatchOptions{ | ||
Content: apiOpts.Content, | ||
SHA: apiOpts.SHA, | ||
Message: apiOpts.Message, | ||
OldBranch: apiOpts.BranchName, | ||
NewBranch: apiOpts.NewBranchName, | ||
Committer: &files.IdentityOptions{ | ||
Name: apiOpts.Committer.Name, | ||
Email: apiOpts.Committer.Email, | ||
}, | ||
Author: &files.IdentityOptions{ | ||
Name: apiOpts.Author.Name, | ||
Email: apiOpts.Author.Email, | ||
}, | ||
Dates: &files.CommitDateOptions{ | ||
Author: apiOpts.Dates.Author, | ||
Committer: apiOpts.Dates.Committer, | ||
}, | ||
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 = "apply-patch" | ||
} | ||
|
||
if !canWriteFiles(ctx.Repo) { | ||
ctx.Error(http.StatusInternalServerError, "ApplyPatch", models.ErrUserDoesNotHaveAccessToRepo{ | ||
UserID: ctx.User.ID, | ||
RepoName: ctx.Repo.Repository.LowerName, | ||
}) | ||
} | ||
|
||
fileResponse, err := files.ApplyDiffPatch(ctx.Repo.Repository, ctx.User, opts) | ||
if err != nil { | ||
if models.IsErrUserCannotCommit(err) || models.IsErrFilePathProtected(err) { | ||
ctx.Error(http.StatusForbidden, "Access", err) | ||
return | ||
} | ||
if models.IsErrBranchAlreadyExists(err) || models.IsErrFilenameInvalid(err) || models.IsErrSHADoesNotMatch(err) || | ||
models.IsErrFilePathInvalid(err) || models.IsErrRepoFileAlreadyExists(err) { | ||
ctx.Error(http.StatusUnprocessableEntity, "Invalid", err) | ||
return | ||
} | ||
if models.IsErrBranchDoesNotExist(err) || git.IsErrBranchNotExist(err) { | ||
ctx.Error(http.StatusNotFound, "BranchDoesNotExist", err) | ||
return | ||
} | ||
ctx.Error(http.StatusInternalServerError, "ApplyPatch", err) | ||
} else { | ||
ctx.JSON(http.StatusCreated, fileResponse) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.