@@ -38,7 +38,7 @@ class Repo(object):
3838
3939 def __init__ (self , cwd , remotes , merges , target ,
4040 shell_command_after = None , fetch_all = False , defaults = None ,
41- force = False ):
41+ force = False , patches = None ):
4242 """Initialize a git repository aggregator
4343
4444 :param cwd: path to the directory where to initialize the repository
@@ -69,6 +69,7 @@ def __init__(self, cwd, remotes, merges, target,
6969 self .shell_command_after = shell_command_after or []
7070 self .defaults = defaults or dict ()
7171 self .force = force
72+ self .patches = patches
7273
7374 @property
7475 def git_version (self ):
@@ -165,6 +166,12 @@ def log_call(self, cmd, callwith=subprocess.check_call,
165166 ret = console_to_str (ret )
166167 return ret
167168
169+ def _apply_patches (self ):
170+ if not self .patches :
171+ return
172+ for patch in self .patches :
173+ self ._patch (patch )
174+
168175 def aggregate (self ):
169176 """ Aggregate all merges into the target branch
170177 If the target_dir doesn't exist, create an empty git repo otherwise
@@ -189,6 +196,7 @@ def aggregate(self):
189196 self ._reset_to (origin ["remote" ], origin ["ref" ])
190197 for merge in merges :
191198 self ._merge (merge )
199+ self ._apply_patches ()
192200 self ._execute_shell_command_after ()
193201 logger .info ('End aggregation of %s' , self .cwd )
194202
@@ -315,6 +323,24 @@ def _merge(self, merge):
315323 cmd += self ._fetch_options (merge ) + (merge ["remote" ], merge ["ref" ])
316324 self .log_call (cmd , cwd = self .cwd )
317325
326+ def _patch (self , patch_path ):
327+ cmd = (
328+ "patch" ,
329+ "-p1" ,
330+ "--no-backup-if-mismatch" ,
331+ "-t" ,
332+ "-i" ,
333+ str (patch_path .resolve ()),
334+ )
335+ if logger .getEffectiveLevel () != logging .DEBUG :
336+ cmd += ('--quiet' ,)
337+ self .log_call (cmd , cwd = self .cwd )
338+ self .log_call (("git" , "add" , "." ), cwd = self .cwd )
339+ self .log_call (
340+ ("git" , "commit" , "-am" , "Applied patch %s" % str (patch_path )),
341+ cwd = self .cwd ,
342+ )
343+
318344 def _get_remotes (self ):
319345 lines = self .log_call (
320346 ['git' , 'remote' , '-v' ],
0 commit comments