Everywhere: Rename "excludePath" to "ignorePattern"
This commit is contained in:
+4
-4
@@ -29,9 +29,9 @@ From there you can copy it to anywhere in the working directory,
|
|||||||
the config file is searched recursively. \\
|
the config file is searched recursively. \\
|
||||||
~$HOME/<dotfiles>/<anywhere>~
|
~$HOME/<dotfiles>/<anywhere>~
|
||||||
|
|
||||||
**** Exclude paths
|
**** Ignore patterns
|
||||||
|
|
||||||
Everything in this list will get excluded when pulling/pushing config files from the working directory. \\
|
Everything in this list will get ignored when pulling/pushing config files from the working directory. \\
|
||||||
Currently two types of file matching are supported:
|
Currently two types of file matching are supported:
|
||||||
|
|
||||||
- ~literal~ matches a file or directory literally
|
- ~literal~ matches a file or directory literally
|
||||||
@@ -44,9 +44,9 @@ These behave similarly to a ~.gitignore~ pattern.
|
|||||||
- If the pattern ends with a slash, it matches only directories. When a directory is ignored, \\
|
- If the pattern ends with a slash, it matches only directories. When a directory is ignored, \\
|
||||||
all of its files and subdirectories are also ignored.
|
all of its files and subdirectories are also ignored.
|
||||||
|
|
||||||
The excluded paths from the example config:
|
The ignore patterns from the example config:
|
||||||
#+BEGIN_SRC javascript
|
#+BEGIN_SRC javascript
|
||||||
"excludePaths" : [
|
"ignorePatterns" : [
|
||||||
".git/",
|
".git/",
|
||||||
"*.md",
|
"*.md",
|
||||||
"manafiles.json",
|
"manafiles.json",
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"excludePaths" : [
|
"ignorePatterns" : [
|
||||||
".git/",
|
".git/",
|
||||||
"*.md",
|
"*.md",
|
||||||
"manafiles.json",
|
"manafiles.json",
|
||||||
|
|||||||
+3
-3
@@ -75,15 +75,15 @@ void Config::parseConfigFile()
|
|||||||
void to_json(nlohmann::json& object, const Settings& settings)
|
void to_json(nlohmann::json& object, const Settings& settings)
|
||||||
{
|
{
|
||||||
object = nlohmann::json {
|
object = nlohmann::json {
|
||||||
{ "excludePaths", settings.excludePaths },
|
{ "ignorePatterns", settings.ignorePatterns },
|
||||||
{ "systemDirectories", settings.systemDirectories }
|
{ "systemDirectories", settings.systemDirectories }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void from_json(const nlohmann::json& object, Settings& settings)
|
void from_json(const nlohmann::json& object, Settings& settings)
|
||||||
{
|
{
|
||||||
if (object.find("excludePaths") != object.end()) {
|
if (object.find("ignorePatterns") != object.end()) {
|
||||||
object.at("excludePaths").get_to(settings.excludePaths);
|
object.at("ignorePatterns").get_to(settings.ignorePatterns);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object.find("systemDirectories") != object.end()) {
|
if (object.find("systemDirectories") != object.end()) {
|
||||||
|
|||||||
+3
-3
@@ -17,7 +17,7 @@
|
|||||||
#include "util/singleton.h"
|
#include "util/singleton.h"
|
||||||
|
|
||||||
struct Settings {
|
struct Settings {
|
||||||
std::vector<std::string> excludePaths {
|
std::vector<std::string> ignorePatterns {
|
||||||
".git/",
|
".git/",
|
||||||
"*.md",
|
"*.md",
|
||||||
"manafiles.json",
|
"manafiles.json",
|
||||||
@@ -38,10 +38,10 @@ public:
|
|||||||
virtual ~Config();
|
virtual ~Config();
|
||||||
|
|
||||||
void setSystemDirectories(const std::vector<std::filesystem::path>& systemDirectories) { m_settings.systemDirectories = systemDirectories; }
|
void setSystemDirectories(const std::vector<std::filesystem::path>& systemDirectories) { m_settings.systemDirectories = systemDirectories; }
|
||||||
void setExcludePaths(const std::vector<std::string>& excludePaths) { m_settings.excludePaths = excludePaths; }
|
void setIgnorePatterns(const std::vector<std::string>& ignorePatterns) { m_settings.ignorePatterns = ignorePatterns; }
|
||||||
void setVerbose(bool verbose) { m_verbose = verbose; }
|
void setVerbose(bool verbose) { m_verbose = verbose; }
|
||||||
|
|
||||||
const std::vector<std::string>& excludePaths() const { return m_settings.excludePaths; }
|
const std::vector<std::string>& ignorePatterns() const { return m_settings.ignorePatterns; }
|
||||||
const std::vector<std::filesystem::path>& systemDirectories() const { return m_settings.systemDirectories; }
|
const std::vector<std::filesystem::path>& systemDirectories() const { return m_settings.systemDirectories; }
|
||||||
|
|
||||||
const std::filesystem::path& workingDirectory() const { return m_workingDirectory; }
|
const std::filesystem::path& workingDirectory() const { return m_workingDirectory; }
|
||||||
|
|||||||
+26
-26
@@ -115,21 +115,21 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
size_t cutFrom = pathString.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0;
|
size_t cutFrom = pathString.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0;
|
||||||
pathString = pathString.substr(cutFrom);
|
pathString = pathString.substr(cutFrom);
|
||||||
|
|
||||||
for (const auto& excludePath : Config::the().excludePaths()) {
|
for (const auto& ignorePattern : Config::the().ignorePatterns()) {
|
||||||
|
|
||||||
if (pathString == excludePath) {
|
if (pathString == ignorePattern) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If starts with '/', only match in the working directory root
|
// If starts with '/', only match in the working directory root
|
||||||
bool onlyMatchInRoot = false;
|
bool onlyMatchInRoot = false;
|
||||||
if (excludePath.front() == '/') {
|
if (ignorePattern.front() == '/') {
|
||||||
onlyMatchInRoot = true;
|
onlyMatchInRoot = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If ends with '/', only match directories
|
// If ends with '/', only match directories
|
||||||
bool onlyMatchDirectories = false;
|
bool onlyMatchDirectories = false;
|
||||||
if (excludePath.back() == '/') {
|
if (ignorePattern.back() == '/') {
|
||||||
onlyMatchDirectories = true;
|
onlyMatchDirectories = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
bool tryPatternState = true;
|
bool tryPatternState = true;
|
||||||
|
|
||||||
size_t pathIterator = 0;
|
size_t pathIterator = 0;
|
||||||
size_t excludeIterator = 0;
|
size_t ignoreIterator = 0;
|
||||||
|
|
||||||
if (!onlyMatchInRoot) {
|
if (!onlyMatchInRoot) {
|
||||||
pathIterator++;
|
pathIterator++;
|
||||||
@@ -148,13 +148,13 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
// Example, iterator at []: [.]log/output.txt
|
// Example, iterator at []: [.]log/output.txt
|
||||||
// [*].log
|
// [*].log
|
||||||
if (pathIterator < pathString.length()
|
if (pathIterator < pathString.length()
|
||||||
&& excludeIterator < excludePath.length() - 1
|
&& ignoreIterator < ignorePattern.length() - 1
|
||||||
&& excludePath.at(excludeIterator) == '*'
|
&& ignorePattern.at(ignoreIterator) == '*'
|
||||||
&& pathString.at(pathIterator) == excludePath.at(excludeIterator + 1)) {
|
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 1)) {
|
||||||
excludeIterator++;
|
ignoreIterator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; pathIterator < pathString.length() && excludeIterator < excludePath.length();) {
|
for (; pathIterator < pathString.length() && ignoreIterator < ignorePattern.length();) {
|
||||||
char character = pathString.at(pathIterator);
|
char character = pathString.at(pathIterator);
|
||||||
pathIterator++;
|
pathIterator++;
|
||||||
|
|
||||||
@@ -167,11 +167,11 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character == excludePath.at(excludeIterator)) {
|
if (character == ignorePattern.at(ignoreIterator)) {
|
||||||
// Fail if the final match hasn't reached the end of the ignore pattern
|
// Fail if the final match hasn't reached the end of the ignore pattern
|
||||||
// Example, iterator at []: doc/buil[d]
|
// Example, iterator at []: doc/buil[d]
|
||||||
// buil[d]/
|
// buil[d]/
|
||||||
if (pathIterator == pathString.length() && excludeIterator < excludePath.length() - 1) {
|
if (pathIterator == pathString.length() && ignoreIterator < ignorePattern.length() - 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,17 +179,17 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
// Example, iterator at []: /includ[e]/header.h
|
// Example, iterator at []: /includ[e]/header.h
|
||||||
// /includ[e]*/
|
// /includ[e]*/
|
||||||
if (pathIterator < pathString.length()
|
if (pathIterator < pathString.length()
|
||||||
&& excludeIterator < excludePath.length() - 2
|
&& ignoreIterator < ignorePattern.length() - 2
|
||||||
&& excludePath.at(excludeIterator + 1) == '*'
|
&& ignorePattern.at(ignoreIterator + 1) == '*'
|
||||||
&& pathString.at(pathIterator) == excludePath.at(excludeIterator + 2)) {
|
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 2)) {
|
||||||
excludeIterator++;
|
ignoreIterator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
excludeIterator++;
|
ignoreIterator++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (excludePath.at(excludeIterator) == '*') {
|
if (ignorePattern.at(ignoreIterator) == '*') {
|
||||||
// Fail if we're entering a subdirectory and we should only match in the root
|
// Fail if we're entering a subdirectory and we should only match in the root
|
||||||
// Example, iterator at []: /src[/]include/header.h
|
// Example, iterator at []: /src[/]include/header.h
|
||||||
// /[*]include/
|
// /[*]include/
|
||||||
@@ -199,9 +199,9 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
|
|
||||||
// Next path character == next ignore pattern character
|
// Next path character == next ignore pattern character
|
||||||
if (pathIterator < pathString.length()
|
if (pathIterator < pathString.length()
|
||||||
&& excludeIterator + 1 < excludePath.length()
|
&& ignoreIterator + 1 < ignorePattern.length()
|
||||||
&& pathString.at(pathIterator) == excludePath.at(excludeIterator + 1)) {
|
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 1)) {
|
||||||
excludeIterator++;
|
ignoreIterator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -210,20 +210,20 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
|||||||
// Reset filter pattern if it hasnt been completed at this point
|
// Reset filter pattern if it hasnt been completed at this point
|
||||||
// Example, iterator at []: /[s]rc/include/header.h
|
// Example, iterator at []: /[s]rc/include/header.h
|
||||||
// /[i]nclude*/
|
// /[i]nclude*/
|
||||||
if (excludeIterator < excludePath.length() - 1) {
|
if (ignoreIterator < ignorePattern.length() - 1) {
|
||||||
excludeIterator = 0;
|
ignoreIterator = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tryPatternState = false;
|
tryPatternState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (excludeIterator == excludePath.length()) {
|
if (ignoreIterator == ignorePattern.length()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (excludePath.back() == '*' && excludeIterator == excludePath.length() - 1) {
|
if (ignorePattern.back() == '*' && ignoreIterator == ignorePattern.length() - 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (onlyMatchDirectories && excludeIterator == excludePath.length() - 1) {
|
if (onlyMatchDirectories && ignoreIterator == ignorePattern.length() - 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ void removeTestDotfiles(const std::vector<std::string>& files, bool deleteInHome
|
|||||||
}
|
}
|
||||||
|
|
||||||
void testDotfileFilters(const std::unordered_map<std::string, bool>& tests,
|
void testDotfileFilters(const std::unordered_map<std::string, bool>& tests,
|
||||||
const std::vector<std::string>& testFilters)
|
const std::vector<std::string>& testIgnorePatterns)
|
||||||
{
|
{
|
||||||
std::vector<std::string> fileNames;
|
std::vector<std::string> fileNames;
|
||||||
std::vector<std::string> fileContents;
|
std::vector<std::string> fileContents;
|
||||||
@@ -93,15 +93,15 @@ void testDotfileFilters(const std::unordered_map<std::string, bool>& tests,
|
|||||||
|
|
||||||
createTestDotfiles(fileNames, fileContents);
|
createTestDotfiles(fileNames, fileContents);
|
||||||
|
|
||||||
auto excludePaths = Config::the().excludePaths();
|
auto ignorePatterns = Config::the().ignorePatterns();
|
||||||
Config::the().setExcludePaths(testFilters);
|
Config::the().setIgnorePatterns(testIgnorePatterns);
|
||||||
|
|
||||||
for (const auto& path : fileNames) {
|
for (const auto& path : fileNames) {
|
||||||
bool result = Dotfile::the().filter(std::filesystem::directory_entry { "/" + path });
|
bool result = Dotfile::the().filter(std::filesystem::directory_entry { "/" + path });
|
||||||
EXPECT_EQ(result, tests.at(path), printf(" path = '%s'\n", path.c_str()));
|
EXPECT_EQ(result, tests.at(path), printf(" path = '%s'\n", path.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::the().setExcludePaths(excludePaths);
|
Config::the().setIgnorePatterns(ignorePatterns);
|
||||||
|
|
||||||
removeTestDotfiles(fileNames, false);
|
removeTestDotfiles(fileNames, false);
|
||||||
}
|
}
|
||||||
@@ -476,7 +476,7 @@ TEST_CASE(PushDotfiles)
|
|||||||
removeTestDotfiles(fileNames);
|
removeTestDotfiles(fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(PushDotfilesWithExcludePath)
|
TEST_CASE(PushDotfilesWithIgnorePattern)
|
||||||
{
|
{
|
||||||
std::vector<std::string> fileNames = {
|
std::vector<std::string> fileNames = {
|
||||||
"__test-file-1",
|
"__test-file-1",
|
||||||
@@ -487,13 +487,16 @@ TEST_CASE(PushDotfilesWithExcludePath)
|
|||||||
|
|
||||||
createTestDotfiles(fileNames, { "", "", "", "" });
|
createTestDotfiles(fileNames, { "", "", "", "" });
|
||||||
|
|
||||||
Config::the().setExcludePaths({
|
auto ignorePatterns = Config::the().ignorePatterns();
|
||||||
|
Config::the().setIgnorePatterns({
|
||||||
"__test-file-1",
|
"__test-file-1",
|
||||||
"__subdir/",
|
"__subdir/",
|
||||||
"*.test",
|
"*.test",
|
||||||
});
|
});
|
||||||
|
|
||||||
Dotfile::the().push(fileNames);
|
Dotfile::the().push(fileNames);
|
||||||
Config::the().setExcludePaths({});
|
|
||||||
|
Config::the().setIgnorePatterns(ignorePatterns);
|
||||||
|
|
||||||
for (const auto& file : fileNames) {
|
for (const auto& file : fileNames) {
|
||||||
EXPECT(!std::filesystem::exists(homeDirectory / file));
|
EXPECT(!std::filesystem::exists(homeDirectory / file));
|
||||||
|
|||||||
Reference in New Issue
Block a user