diff --git a/cli/pathmatch.cpp b/cli/pathmatch.cpp index 25ed6cd71..270f5c1da 100644 --- a/cli/pathmatch.cpp +++ b/cli/pathmatch.cpp @@ -35,7 +35,14 @@ bool PathMatch::Match(const std::string &path) if (findpath[findpath.length() - 1] != '/') findpath = RemoveFilename(findpath); - if (findpath.find(*iterMask) != std::string::npos) + // Match relative paths starting with mask + // -isrc matches src/foo.cpp + if (findpath.compare(0, (*iterMask).size(), *iterMask) == 0) + return true; + // Match only full directory name in middle or end of the path + // -isrc matches myproject/src/ but does not match + // myproject/srcfiles/ or myproject/mysrc/ + if (findpath.find("/" + *iterMask) != std::string::npos) return true; } return false; diff --git a/test/testpathmatch.cpp b/test/testpathmatch.cpp index dadeef311..f929308e7 100644 --- a/test/testpathmatch.cpp +++ b/test/testpathmatch.cpp @@ -38,6 +38,10 @@ private: TEST_CASE(onemaskemptypath); TEST_CASE(onemasksamepath); TEST_CASE(onemasksamepathwithfile); + TEST_CASE(onemaskdifferentdir1); + TEST_CASE(onemaskdifferentdir2); + TEST_CASE(onemaskdifferentdir3); + TEST_CASE(onemaskdifferentdir4); TEST_CASE(onemasklongerpath1); TEST_CASE(onemasklongerpath2); TEST_CASE(onemasklongerpath3); @@ -95,6 +99,38 @@ private: ASSERT(match.Match("src/file.txt")); } + void onemaskdifferentdir1() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("srcfiles/file.txt")); + } + + void onemaskdifferentdir2() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("proj/srcfiles/file.txt")); + } + + void onemaskdifferentdir3() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("proj/mysrc/file.txt")); + } + + void onemaskdifferentdir4() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("proj/mysrcfiles/file.txt")); + } + void onemasklongerpath1() { std::vector masks;