mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Add apply-patch, basic revert and cherry-pick functionality (#17902)
This code adds a simple endpoint to apply patches to repositories and branches on gitea. This is then used along with the conflicting checking code in #18004 to provide a basic implementation of cherry-pick revert. Now because the buttons necessary for cherry-pick and revert have required us to create a dropdown next to the Browse Source button I've also implemented Create Branch and Create Tag operations. Fix #3880 Fix #17986 Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		@@ -32,6 +32,21 @@ func GetRawDiff(ctx context.Context, repoPath, commitID string, diffType RawDiff
 | 
			
		||||
	return GetRawDiffForFile(ctx, repoPath, "", commitID, diffType, "", writer)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
 | 
			
		||||
func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io.Writer) error {
 | 
			
		||||
	stderr := new(bytes.Buffer)
 | 
			
		||||
	cmd := NewCommand(ctx, "show", "--pretty=format:revert %H%n", "-R", commitID)
 | 
			
		||||
	if err := cmd.RunWithContext(&RunContext{
 | 
			
		||||
		Timeout: -1,
 | 
			
		||||
		Dir:     repoPath,
 | 
			
		||||
		Stdout:  writer,
 | 
			
		||||
		Stderr:  stderr,
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
		return fmt.Errorf("Run: %v - %s", err, stderr)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetRawDiffForFile dumps diff results of file in given commit ID to io.Writer.
 | 
			
		||||
func GetRawDiffForFile(ctx context.Context, repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
 | 
			
		||||
	repo, closer, err := RepositoryFromContextOrOpen(ctx, repoPath)
 | 
			
		||||
@@ -221,8 +236,7 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	err := scanner.Err()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	if err := scanner.Err(); err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user