diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2022-05-04 21:20:45 +0900 |
---|---|---|
committer | Ryooooooga <eial5q265e5@gmail.com> | 2022-05-06 21:53:00 +0900 |
commit | d458e78d95132a894d0577a31b3af643f070b3e6 (patch) | |
tree | e04239847d4b029c7caed877b4e48f13d7ba8e76 /pkg/commands | |
parent | 0940e0182b7d9ecba1a5f222b77f0d678753e9d5 (diff) |
feat: add ability to edit hunk
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/working_tree.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index cac93385a..5986392a8 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -255,12 +255,15 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain } func (self *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error { - filepath := filepath.Join(self.os.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch") - self.Log.Infof("saving temporary patch to %s", filepath) - if err := self.os.CreateFileWithContent(filepath, patch); err != nil { + filepath, err := self.SaveTemporaryPatch(patch) + if err != nil { return err } + return self.ApplyPatchFile(filepath, flags...) +} + +func (self *WorkingTreeCommands) ApplyPatchFile(filepath string, flags ...string) error { flagStr := "" for _, flag := range flags { flagStr += " --" + flag @@ -269,6 +272,15 @@ func (self *WorkingTreeCommands) ApplyPatch(patch string, flags ...string) error return self.cmd.New(fmt.Sprintf("git apply%s %s", flagStr, self.cmd.Quote(filepath))).Run() } +func (self *WorkingTreeCommands) SaveTemporaryPatch(patch string) (string, error) { + filepath := filepath.Join(self.os.GetTempDir(), utils.GetCurrentRepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".patch") + self.Log.Infof("saving temporary patch to %s", filepath) + if err := self.os.CreateFileWithContent(filepath, patch); err != nil { + return "", err + } + return filepath, nil +} + // ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc // but when we're in diff mode it could be any 'from' to any 'to'. The reverse flag is also here thanks to diff mode. func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool) (string, error) { |