@@ -173,28 +173,19 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchIntoWorkingTree() error
173
173
174
174
self .returnFocusFromPatchExplorerIfNecessary ()
175
175
176
- pull := func (stash bool ) error {
177
- return self .c .WithWaitingStatus (self .c .Tr .RebasingStatus , func (gocui.Task ) error {
178
- commitIndex := self .getPatchCommitIndex ()
179
- self .c .LogAction (self .c .Tr .Actions .MovePatchIntoIndex )
180
- err := self .c .Git ().Patch .MovePatchIntoIndex (self .c .Model ().Commits , commitIndex , stash )
181
- return self .c .Helpers ().MergeAndRebase .CheckMergeOrRebase (err )
182
- })
183
- }
184
-
185
- if self .c .Helpers ().WorkingTree .IsWorkingTreeDirty () {
186
- self .c .Confirm (types.ConfirmOpts {
187
- Title : self .c .Tr .MustStashTitle ,
188
- Prompt : self .c .Tr .MustStashWarning ,
189
- HandleConfirm : func () error {
190
- return pull (true )
191
- },
192
- })
193
-
194
- return nil
195
- }
196
-
197
- return pull (false )
176
+ mustStash := self .c .Helpers ().WorkingTree .IsWorkingTreeDirty ()
177
+ return self .c .ConfirmIf (mustStash , types.ConfirmOpts {
178
+ Title : self .c .Tr .MustStashTitle ,
179
+ Prompt : self .c .Tr .MustStashWarning ,
180
+ HandleConfirm : func () error {
181
+ return self .c .WithWaitingStatus (self .c .Tr .RebasingStatus , func (gocui.Task ) error {
182
+ commitIndex := self .getPatchCommitIndex ()
183
+ self .c .LogAction (self .c .Tr .Actions .MovePatchIntoIndex )
184
+ err := self .c .Git ().Patch .MovePatchIntoIndex (self .c .Model ().Commits , commitIndex , mustStash )
185
+ return self .c .Helpers ().MergeAndRebase .CheckMergeOrRebase (err )
186
+ })
187
+ },
188
+ })
198
189
}
199
190
200
191
func (self * CustomPatchOptionsMenuAction ) handlePullPatchIntoNewCommit () error {
@@ -272,40 +263,31 @@ func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
272
263
273
264
affectedUnstagedFiles := self .getAffectedUnstagedFiles ()
274
265
275
- apply := func () error {
276
- action := self .c .Tr .Actions .ApplyPatch
277
- if reverse {
278
- action = "Apply patch in reverse"
279
- }
280
- self .c .LogAction (action )
281
-
282
- if len (affectedUnstagedFiles ) > 0 {
283
- if err := self .c .Git ().WorkingTree .StageFiles (affectedUnstagedFiles , nil ); err != nil {
284
- return err
266
+ mustStageFiles := len (affectedUnstagedFiles ) > 0
267
+ return self .c .ConfirmIf (mustStageFiles , types.ConfirmOpts {
268
+ Title : self .c .Tr .MustStageFilesAffectedByPatchTitle ,
269
+ Prompt : self .c .Tr .MustStageFilesAffectedByPatchWarning ,
270
+ HandleConfirm : func () error {
271
+ action := self .c .Tr .Actions .ApplyPatch
272
+ if reverse {
273
+ action = "Apply patch in reverse"
285
274
}
286
- }
275
+ self . c . LogAction ( action )
287
276
288
- if err := self .c .Git ().Patch .ApplyCustomPatch (reverse , true ); err != nil {
289
- return err
290
- }
291
-
292
- self .c .Refresh (types.RefreshOptions {Mode : types .ASYNC })
293
- return nil
294
- }
295
-
296
- if len (affectedUnstagedFiles ) > 0 {
297
- self .c .Confirm (types.ConfirmOpts {
298
- Title : self .c .Tr .MustStageFilesAffectedByPatchTitle ,
299
- Prompt : self .c .Tr .MustStageFilesAffectedByPatchWarning ,
300
- HandleConfirm : func () error {
301
- return apply ()
302
- },
303
- })
277
+ if mustStageFiles {
278
+ if err := self .c .Git ().WorkingTree .StageFiles (affectedUnstagedFiles , nil ); err != nil {
279
+ return err
280
+ }
281
+ }
304
282
305
- return nil
306
- }
283
+ if err := self .c .Git ().Patch .ApplyCustomPatch (reverse , true ); err != nil {
284
+ return err
285
+ }
307
286
308
- return apply ()
287
+ self .c .Refresh (types.RefreshOptions {Mode : types .ASYNC })
288
+ return nil
289
+ },
290
+ })
309
291
}
310
292
311
293
func (self * CustomPatchOptionsMenuAction ) copyPatchToClipboard () error {
0 commit comments