comparison tests/test-hgignore.t @ 49603:3eda36e9b3d6 stable

matcher: fix issues regex flag contained in pattern (issue6759) Python 3.11 is now enforcing that flag must be at the beginning of the regex This creates a serious regression for people using Python 3.11 with an hgignore using flag in a "relre" pattern. We now detect any flags in such pattern and "prepend" our ".*" pattern after them. In addition, we now insert the flag in the regexp to only affect the pattern we are rewriting. Otherwise, the regex built from the combined pattern would these flags in the middle of it anyway. As a side effect of this last change, we fix a bug… before this change regex flag in a pattern would affect all combined patterns. That was bad and is not longer the case. The Rust code needs to be updated to fix that very bug, but we will do it in another changeset.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 16 Nov 2022 13:05:01 +0100
parents 363923bd51cd
children 086b0c4f8663
comparison
equal deleted inserted replaced
49602:4e3d86565327 49603:3eda36e9b3d6
60 60
61 $ echo "*.o" > .hgignore 61 $ echo "*.o" > .hgignore
62 $ hg status 62 $ hg status
63 abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob) 63 abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob)
64 [255] 64 [255]
65
66 Test relre with flags (issue6759)
67 ---------------------------------
68
69 regexp with flag is the first one
70
71 $ echo 're:(?i)\.O$' > .hgignore
72 $ echo 're:.hgignore' >> .hgignore
73 $ hg status
74 A dir/b.o
75 ? a.c
76 ? syntax
77
78 regex with flag is not the first one
79
80 $ echo 're:.hgignore' > .hgignore
81 $ echo 're:(?i)\.O$' >> .hgignore
82 $ hg status
83 A dir/b.o
84 ? a.c
85 ? syntax
86
87 flag in a pattern should affect that pattern only
88
89 $ echo 're:(?i)\.O$' > .hgignore
90 $ echo 're:.HGIGNORE' >> .hgignore
91 $ hg status
92 A dir/b.o
93 ? .hgignore (no-rust !)
94 ? .hgignore (rust missing-correct-output !)
95 ? a.c
96 ? syntax
97
98 $ echo 're:.HGIGNORE' > .hgignore
99 $ echo 're:(?i)\.O$' >> .hgignore
100 $ hg status
101 A dir/b.o
102 ? .hgignore
103 ? a.c
104 ? syntax
105
106
107 further testing
108 ---------------
65 109
66 $ echo 're:^(?!a).*\.o$' > .hgignore 110 $ echo 're:^(?!a).*\.o$' > .hgignore
67 $ hg status 111 $ hg status
68 A dir/b.o 112 A dir/b.o
69 ? .hgignore 113 ? .hgignore