@@ -282,18 +282,15 @@ def apply(self, args, yml, mods=None):
282282 patched_mods .add (mod )
283283
284284 self .dbg (f"patching { mod } ... " , end = "" )
285- origdir = os .getcwd ()
286- os .chdir (mod_path )
287285 apply_cmd += patch_path
288286 apply_cmd_list .extend ([patch_path ])
289- proc = subprocess .run (apply_cmd_list )
287+ proc = subprocess .run (apply_cmd_list , cwd = mod_path )
290288 if proc .returncode :
291289 self .dbg ("FAIL" )
292290 self .err (proc .stderr )
293291 failed_patch = pth
294292 break
295293 self .dbg ("OK" )
296- os .chdir (origdir )
297294
298295 if not failed_patch :
299296 self .inf (f"{ patch_count } patches applied successfully \\ o/" )
@@ -302,7 +299,7 @@ def apply(self, args, yml, mods=None):
302299 if args .roll_back :
303300 self .clean (args , yml , patched_mods )
304301
305- self .die (f"failed to apply patch { pth } " )
302+ self .die (f"failed to apply patch { failed_patch } " )
306303
307304 def clean (self , args , yml , mods = None ):
308305 clean_cmd = yml ["clean-command" ]
@@ -315,16 +312,13 @@ def clean(self, args, yml, mods=None):
315312 clean_cmd_list = shlex .split (clean_cmd )
316313 checkout_cmd_list = shlex .split (checkout_cmd )
317314
318- origdir = os .getcwd ()
319315 for mod , mod_path in Patch .get_mod_paths (args , yml ).items ():
320316 if mods and mod not in mods :
321317 continue
322318 try :
323- os .chdir (mod_path )
324-
325319 if checkout_cmd :
326320 self .dbg (f"Running '{ checkout_cmd } ' in { mod } .. " , end = "" )
327- proc = subprocess .run (checkout_cmd_list , capture_output = True )
321+ proc = subprocess .run (checkout_cmd_list , capture_output = True , cwd = mod_path )
328322 if proc .returncode :
329323 self .dbg ("FAIL" )
330324 self .err (f"{ checkout_cmd } failed for { mod } \n { proc .stderr } " )
@@ -333,7 +327,7 @@ def clean(self, args, yml, mods=None):
333327
334328 if clean_cmd :
335329 self .dbg (f"Running '{ clean_cmd } ' in { mod } .. " , end = "" )
336- proc = subprocess .run (clean_cmd_list , capture_output = True )
330+ proc = subprocess .run (clean_cmd_list , capture_output = True , cwd = mod_path )
337331 if proc .returncode :
338332 self .dbg ("FAIL" )
339333 self .err (f"{ clean_cmd } failed for { mod } \n { proc .stderr } " )
@@ -344,8 +338,6 @@ def clean(self, args, yml, mods=None):
344338 # If this fails for some reason, just log it and continue
345339 self .err (f"failed to clean up { mod } : { e } " )
346340
347- os .chdir (origdir )
348-
349341 def list (self , args , yml , mods = None ):
350342 patches = yml .get ("patches" , [])
351343 if not patches :
0 commit comments