Skip to content

Commit bc341c8

Browse files
pcloudsgitster
authored andcommitted
pathspec: catch prepending :(prefix) on pathspec with short magic
:(prefix) is in the long form. Suppose people pass :!foo with '!' being the short form of magic 'bar', the code will happily turn it to :(prefix..)!foo, which makes '!' part of the path and no longer a magic. The correct form must be ':(prefix..,bar)foo', but as so far we haven't had any magic in short form yet (*), the code to convert from short form to long one will be inactive anyway. Let's postpone it until a real short form magic appears. (*) The short form magic '/' is a special case and won't be caught by this die(), which is correct. When '/' magic is detected, prefixlen is set back to 0 and the whole "if (prefixlen..)" block is skipped. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4838c81 commit bc341c8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pathspec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
231231
const char *start = elt;
232232
if (prefixlen && !literal_global) {
233233
/* Preserve the actual prefix length of each pattern */
234-
if (long_magic_end) {
234+
if (short_magic)
235+
die("BUG: prefixing on short magic is not supported");
236+
else if (long_magic_end) {
235237
strbuf_add(&sb, start, long_magic_end - start);
236238
strbuf_addf(&sb, ",prefix:%d", prefixlen);
237239
start = long_magic_end;

0 commit comments

Comments
 (0)