qkpr 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +20 -19
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1237,7 +1237,7 @@ inquirer.registerPrompt("search-checkbox", searchCheckbox);
|
|
|
1237
1237
|
* 通用的分支选择函数,支持单选和多选
|
|
1238
1238
|
*/
|
|
1239
1239
|
async function promptBranchSelection(branches, options) {
|
|
1240
|
-
const { title, message, mode, filterPinned = false } = options;
|
|
1240
|
+
const { title, message, mode, filterPinned = false, defaultSelected = [] } = options;
|
|
1241
1241
|
console.log(cyan(`\n${title}`));
|
|
1242
1242
|
console.log(dim(""));
|
|
1243
1243
|
if (branches.length === 0) {
|
|
@@ -1262,7 +1262,8 @@ async function promptBranchSelection(branches, options) {
|
|
|
1262
1262
|
choices.push({
|
|
1263
1263
|
name: `📌 ${branch.name.padEnd(45)} ${dim(`(${branch.lastCommitTimeFormatted})`)}`,
|
|
1264
1264
|
value: branch.name,
|
|
1265
|
-
short: branch.name
|
|
1265
|
+
short: branch.name,
|
|
1266
|
+
checked: defaultSelected.includes(branch.name)
|
|
1266
1267
|
});
|
|
1267
1268
|
});
|
|
1268
1269
|
choices.push(new inquirer.Separator(" "));
|
|
@@ -1273,7 +1274,8 @@ async function promptBranchSelection(branches, options) {
|
|
|
1273
1274
|
choices.push({
|
|
1274
1275
|
name: ` ${branch.name.padEnd(45)} ${dim(`(${branch.lastCommitTimeFormatted})`)}`,
|
|
1275
1276
|
value: branch.name,
|
|
1276
|
-
short: branch.name
|
|
1277
|
+
short: branch.name,
|
|
1278
|
+
checked: defaultSelected.includes(branch.name)
|
|
1277
1279
|
});
|
|
1278
1280
|
});
|
|
1279
1281
|
choices.push(new inquirer.Separator(" "));
|
|
@@ -1300,7 +1302,7 @@ async function promptBranchSelection(branches, options) {
|
|
|
1300
1302
|
type: "search-checkbox",
|
|
1301
1303
|
name: "selectedBranches",
|
|
1302
1304
|
message,
|
|
1303
|
-
choices
|
|
1305
|
+
choices: choices.filter((c) => c.value)
|
|
1304
1306
|
}]);
|
|
1305
1307
|
return selectedBranches || [];
|
|
1306
1308
|
}
|
|
@@ -1368,25 +1370,24 @@ async function handlePinCommand(branchName) {
|
|
|
1368
1370
|
return;
|
|
1369
1371
|
}
|
|
1370
1372
|
const pinnedBranches = getPinnedBranches();
|
|
1371
|
-
const
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
return;
|
|
1375
|
-
}
|
|
1376
|
-
const selectedBranches = await promptBranchSelection(availableBranches, {
|
|
1377
|
-
title: "📌 Pin Branches",
|
|
1378
|
-
message: "Select branches to pin (type to search, Space to select, Enter to confirm):",
|
|
1373
|
+
const selectedBranches = await promptBranchSelection(branches, {
|
|
1374
|
+
title: "📌 Manage Pinned Branches",
|
|
1375
|
+
message: "Select branches to pin (type to search, Space to toggle, Enter to confirm):",
|
|
1379
1376
|
mode: "multiple",
|
|
1380
|
-
|
|
1377
|
+
defaultSelected: pinnedBranches
|
|
1381
1378
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
selectedBranches.forEach((branch) => {
|
|
1379
|
+
const toAdd = selectedBranches.filter((b) => !pinnedBranches.includes(b));
|
|
1380
|
+
const toRemove = pinnedBranches.filter((b) => !selectedBranches.includes(b));
|
|
1381
|
+
toAdd.forEach((branch) => {
|
|
1387
1382
|
addPinnedBranch(branch);
|
|
1388
1383
|
});
|
|
1389
|
-
|
|
1384
|
+
toRemove.forEach((branch) => {
|
|
1385
|
+
removePinnedBranch(branch);
|
|
1386
|
+
});
|
|
1387
|
+
if (toAdd.length > 0 || toRemove.length > 0) {
|
|
1388
|
+
if (toAdd.length > 0) console.log(green(`✅ Pinned ${toAdd.length} branch(es)`));
|
|
1389
|
+
if (toRemove.length > 0) console.log(green(`✅ Unpinned ${toRemove.length} branch(es)`));
|
|
1390
|
+
} else console.log(dim("No changes made"));
|
|
1390
1391
|
}
|
|
1391
1392
|
const updatedPinnedBranches = getPinnedBranches();
|
|
1392
1393
|
console.log(cyan("\n📌 Current pinned branches:"));
|