Permalink
Browse files

Merge pull request #687 from shijinglu/fix_rm_overmatch

Fix git-meta rm path overmatching issue
  • Loading branch information...
shijinglu committed Nov 10, 2018
2 parents 3e6d885 + 984180c commit 26f63d778fb441eb3efac417c9158e7af3ec5dea
Showing with 14 additions and 2 deletions.
  1. +0 −1 node/lib/util/merge_util.js
  2. +9 −1 node/lib/util/submodule_util.js
  3. +5 −0 node/test/util/submodule_util.js
@@ -38,7 +38,6 @@ const NodeGit = require("nodegit");

const Checkout = require("./checkout");
const CherryPickUtil = require("./cherry_pick_util");
const Commit = require("./commit");
const ConfigUtil = require("./config_util");
const DoWorkQueue = require("./do_work_queue");
const GitUtil = require("./git_util");
@@ -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);
}
}
@@ -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];

0 comments on commit 26f63d7

Please sign in to comment.