19
19
#include "utf8.h"
20
20
#include "dir.h"
21
21
#include "color.h"
22
+ #include "refs.h"
22
23
23
24
struct config_source {
24
25
struct config_source * prev ;
@@ -170,6 +171,12 @@ static int handle_path_include(const char *path, struct config_include_data *inc
170
171
return ret ;
171
172
}
172
173
174
+ static void add_trailing_starstar_for_dir (struct strbuf * pat )
175
+ {
176
+ if (pat -> len && is_dir_sep (pat -> buf [pat -> len - 1 ]))
177
+ strbuf_addstr (pat , "**" );
178
+ }
179
+
173
180
static int prepare_include_condition_pattern (struct strbuf * pat )
174
181
{
175
182
struct strbuf path = STRBUF_INIT ;
@@ -199,8 +206,7 @@ static int prepare_include_condition_pattern(struct strbuf *pat)
199
206
} else if (!is_absolute_path (pat -> buf ))
200
207
strbuf_insert (pat , 0 , "**/" , 3 );
201
208
202
- if (pat -> len && is_dir_sep (pat -> buf [pat -> len - 1 ]))
203
- strbuf_addstr (pat , "**" );
209
+ add_trailing_starstar_for_dir (pat );
204
210
205
211
strbuf_release (& path );
206
212
return prefix ;
@@ -264,6 +270,25 @@ static int include_by_gitdir(const struct config_options *opts,
264
270
return ret ;
265
271
}
266
272
273
+ static int include_by_branch (const char * cond , size_t cond_len )
274
+ {
275
+ int flags ;
276
+ int ret ;
277
+ struct strbuf pattern = STRBUF_INIT ;
278
+ const char * refname = resolve_ref_unsafe ("HEAD" , 0 , NULL , & flags );
279
+ const char * shortname ;
280
+
281
+ if (!refname || !(flags & REF_ISSYMREF ) ||
282
+ !skip_prefix (refname , "refs/heads/" , & shortname ))
283
+ return 0 ;
284
+
285
+ strbuf_add (& pattern , cond , cond_len );
286
+ add_trailing_starstar_for_dir (& pattern );
287
+ ret = !wildmatch (pattern .buf , shortname , WM_PATHNAME );
288
+ strbuf_release (& pattern );
289
+ return ret ;
290
+ }
291
+
267
292
static int include_condition_is_true (const struct config_options * opts ,
268
293
const char * cond , size_t cond_len )
269
294
{
@@ -272,6 +297,8 @@ static int include_condition_is_true(const struct config_options *opts,
272
297
return include_by_gitdir (opts , cond , cond_len , 0 );
273
298
else if (skip_prefix_mem (cond , cond_len , "gitdir/i:" , & cond , & cond_len ))
274
299
return include_by_gitdir (opts , cond , cond_len , 1 );
300
+ else if (skip_prefix_mem (cond , cond_len , "onbranch:" , & cond , & cond_len ))
301
+ return include_by_branch (cond , cond_len );
275
302
276
303
/* unknown conditionals are always false */
277
304
return 0 ;
0 commit comments