diff options
Diffstat (limited to 'pkg/commands/git_commands/working_tree.go')
-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) { |