Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git-meta rm path overmatching issue #687

Merged
merged 2 commits into from Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion node/lib/util/merge_util.js
Expand Up @@ -38,7 +38,6 @@ const NodeGit = require("nodegit");

const Checkout = require("./checkout");
const CherryPickUtil = require("./cherry_pick_util");
const Commit = require("./commit");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed according to jslint

const ConfigUtil = require("./config_util");
const DoWorkQueue = require("./do_work_queue");
const GitUtil = require("./git_util");
Expand Down
10 changes: 9 additions & 1 deletion node/lib/util/submodule_util.js
Expand Up @@ -559,11 +559,19 @@ exports.getSubmodulesInPath = function (dir, indexSubNames) {
if ("" === dir) {
return indexSubNames;
}

// test if the short path a parent dir of the long path
const isParentDir = (short, long) => {
return long.startsWith(short) && (
short[short.length-1] === "/" ||
long[short.length] === "/"
);
};
const result = [];
for (const subPath of indexSubNames) {
if (subPath === dir) {
return [dir]; // RETURN
} else if (subPath.startsWith(dir)) {
} else if (isParentDir(dir, subPath)) {
result.push(subPath);
}
}
Expand Down
5 changes: 5 additions & 0 deletions node/test/util/submodule_util.js
Expand Up @@ -781,6 +781,11 @@ describe("SubmoduleUtil", function () {
indexSubNames: ["q/r", "q/s", "q/t/v", "z"],
expected: ["q/r", "q/s", "q/t/v"],
},
"does not overmatch": {
dir: "q",
indexSubNames: ["q/r", "qr", "qr/"],
expected: ["q/r"],
},
};
Object.keys(cases).forEach(caseName => {
const c = cases[caseName];
Expand Down