This commit is contained in:
climatex 2026-08-30 14:01:24 -07:00 committed by GitHub
commit 83c5a9b052
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 0 deletions

View file

@ -3,6 +3,8 @@ package controllers
import (
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@ -104,6 +106,12 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
}
menuItems = append(menuItems, []*types.MenuItem{
{
Label: self.c.Tr.SavePatch,
Tooltip: self.c.Tr.SavePatchTooltip,
OnPress: self.handleSavePatchToFile,
Key: 's',
},
{
Label: self.c.Tr.CopyPatchToClipboard,
OnPress: func() error { return self.copyPatchToClipboard() },
@ -275,6 +283,31 @@ func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
})
}
func (self *CustomPatchOptionsMenuAction) handleSavePatchToFile() error {
patch := self.c.Git().Patch.PatchBuilder.RenderAggregatedPatch(true)
self.c.Prompt(types.PromptOpts{
Title: self.c.Tr.SavePatchTitle,
HandleConfirm: func(path string) error {
path = strings.TrimSpace(path)
if !filepath.IsAbs(path) {
path = filepath.Join(self.c.Git().RepoPaths.WorktreePath(), path)
}
path = filepath.Clean(path)
self.c.LogAction(self.c.Tr.Actions.SavePatchToFile)
if err := self.c.OS().CreateFileWithContent(path, patch); err != nil {
return err
}
self.c.Toast(fmt.Sprintf(self.c.Tr.PatchSavedToFile, path))
return nil
},
})
return nil
}
func (self *CustomPatchOptionsMenuAction) copyPatchToClipboard() error {
patch := self.c.Git().Patch.PatchBuilder.RenderAggregatedPatch(true)

View file

@ -870,6 +870,10 @@ type TranslationSet struct {
MovePatchIntoNewCommitBeforeTooltip string
MovePatchToSelectedCommit string
MovePatchToSelectedCommitTooltip string
SavePatch string
SavePatchTooltip string
SavePatchTitle string
PatchSavedToFile string
CopyPatchToClipboard string
MustStageFilesAffectedByPatchTitle string
MustStageFilesAffectedByPatchWarning string
@ -1051,6 +1055,7 @@ type Actions struct {
CopyCommitAttributeToClipboard string
CopyCommitTagsToClipboard string
CopyPatchToClipboard string
SavePatchToFile string
CustomCommand string
DiscardAllChangesInFile string
DiscardAllUnstagedChangesInFile string
@ -2029,6 +2034,10 @@ func EnglishTranslationSet() *TranslationSet {
MovePatchIntoNewCommitBeforeTooltip: "Move the patch out of its commit and into a new commit before the original commit. This works best when the custom patch contains only entire hunks or even entire files; if it contains partial hunks, you are likely to get conflicts.",
MovePatchToSelectedCommit: "Move patch to selected commit (%s)",
MovePatchToSelectedCommitTooltip: "Move the patch out of its original commit and into the selected commit. This is achieved by starting an interactive rebase at the original commit, applying the patch in reverse, then continuing the rebase up to the selected commit, before applying the patch forward and amending the selected commit. The rebase is then continued to completion. If commits between the source and destination commit depend on the patch, you may need to resolve conflicts.",
SavePatch: "Save patch to file",
SavePatchTooltip: "Write the current patch to a file. Relative paths are resolved from the repository root.",
SavePatchTitle: "Save patch to file",
PatchSavedToFile: "Patch saved to %s",
CopyPatchToClipboard: "Copy patch to clipboard",
MustStageFilesAffectedByPatchTitle: "Must stage files",
MustStageFilesAffectedByPatchWarning: "Applying a patch to the index requires staging the unstaged files that are affected by the patch. Note that you might get conflicts when applying the patch. Continue?",
@ -2167,6 +2176,7 @@ func EnglishTranslationSet() *TranslationSet {
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
CopyCommitAttributeToClipboard: "Copy to clipboard",
CopyPatchToClipboard: "Copy patch to clipboard",
SavePatchToFile: "Save patch to file",
MoveCommitUp: "Move commit up",
MoveCommitDown: "Move commit down",
CustomCommand: "Custom command",