@@ -38,7 +38,7 @@ class Repo(object):
38
38
39
39
def __init__ (self , cwd , remotes , merges , target ,
40
40
shell_command_after = None , fetch_all = False , defaults = None ,
41
- force = False ):
41
+ force = False , patches = None ):
42
42
"""Initialize a git repository aggregator
43
43
44
44
:param cwd: path to the directory where to initialize the repository
@@ -69,6 +69,7 @@ def __init__(self, cwd, remotes, merges, target,
69
69
self .shell_command_after = shell_command_after or []
70
70
self .defaults = defaults or dict ()
71
71
self .force = force
72
+ self .patches = patches
72
73
73
74
@property
74
75
def git_version (self ):
@@ -165,6 +166,12 @@ def log_call(self, cmd, callwith=subprocess.check_call,
165
166
ret = console_to_str (ret )
166
167
return ret
167
168
169
+ def _apply_patches (self ):
170
+ if not self .patches :
171
+ return
172
+ for patch in self .patches :
173
+ self ._patch (patch )
174
+
168
175
def aggregate (self ):
169
176
""" Aggregate all merges into the target branch
170
177
If the target_dir doesn't exist, create an empty git repo otherwise
@@ -189,6 +196,7 @@ def aggregate(self):
189
196
self ._reset_to (origin ["remote" ], origin ["ref" ])
190
197
for merge in merges :
191
198
self ._merge (merge )
199
+ self ._apply_patches ()
192
200
self ._execute_shell_command_after ()
193
201
logger .info ('End aggregation of %s' , self .cwd )
194
202
@@ -315,6 +323,24 @@ def _merge(self, merge):
315
323
cmd += self ._fetch_options (merge ) + (merge ["remote" ], merge ["ref" ])
316
324
self .log_call (cmd , cwd = self .cwd )
317
325
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
+
318
344
def _get_remotes (self ):
319
345
lines = self .log_call (
320
346
['git' , 'remote' , '-v' ],
0 commit comments