@quikcommit/cli 9.0.0 → 10.0.0
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.js +89 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7879,6 +7879,26 @@ function getStagedFiles() {
|
|
|
7879
7879
|
encoding: "utf-8"
|
|
7880
7880
|
});
|
|
7881
7881
|
}
|
|
7882
|
+
function getWorkingTreeDiff(excludes = []) {
|
|
7883
|
+
const args = ["diff", "HEAD"];
|
|
7884
|
+
if (excludes.length > 0) {
|
|
7885
|
+
args.push("--");
|
|
7886
|
+
args.push(".");
|
|
7887
|
+
for (const pattern of excludes) {
|
|
7888
|
+
args.push(`:(exclude)${pattern}`);
|
|
7889
|
+
}
|
|
7890
|
+
}
|
|
7891
|
+
return (0, import_child_process2.execFileSync)("git", args, {
|
|
7892
|
+
encoding: "utf-8",
|
|
7893
|
+
maxBuffer: 10 * 1024 * 1024
|
|
7894
|
+
});
|
|
7895
|
+
}
|
|
7896
|
+
function getAllChangedFiles() {
|
|
7897
|
+
const output = (0, import_child_process2.execFileSync)("git", ["status", "--porcelain"], {
|
|
7898
|
+
encoding: "utf-8"
|
|
7899
|
+
});
|
|
7900
|
+
return output.trim().split("\n").filter(Boolean).map((line) => line.slice(3)).join("\n");
|
|
7901
|
+
}
|
|
7882
7902
|
function hasStagedChanges() {
|
|
7883
7903
|
const output = (0, import_child_process2.execFileSync)("git", ["diff", "--cached", "--name-only"], {
|
|
7884
7904
|
encoding: "utf-8"
|
|
@@ -7889,17 +7909,21 @@ function getUnstagedFiles() {
|
|
|
7889
7909
|
const output = (0, import_child_process2.execFileSync)("git", ["status", "--porcelain"], {
|
|
7890
7910
|
encoding: "utf-8"
|
|
7891
7911
|
});
|
|
7892
|
-
return output.trim().split("\n").filter(Boolean)
|
|
7912
|
+
return output.trim().split("\n").filter(Boolean);
|
|
7893
7913
|
}
|
|
7894
7914
|
function stageAll() {
|
|
7895
|
-
(0, import_child_process2.execFileSync)("git", ["add", "-
|
|
7915
|
+
(0, import_child_process2.execFileSync)("git", ["add", "-A"], { stdio: "pipe" });
|
|
7896
7916
|
}
|
|
7897
7917
|
function gitCommit(message) {
|
|
7898
7918
|
const tmpDir = (0, import_fs2.mkdtempSync)((0, import_path2.join)((0, import_os3.tmpdir)(), "qc-"));
|
|
7899
7919
|
const tmpFile = (0, import_path2.join)(tmpDir, "commit.txt");
|
|
7900
7920
|
(0, import_fs2.writeFileSync)(tmpFile, message, { mode: 384 });
|
|
7901
7921
|
try {
|
|
7902
|
-
(0, import_child_process2.execFileSync)("git", ["commit", "-F", tmpFile], { stdio: "
|
|
7922
|
+
(0, import_child_process2.execFileSync)("git", ["commit", "-F", tmpFile], { stdio: "pipe" });
|
|
7923
|
+
} catch (err) {
|
|
7924
|
+
const stderr = err?.stderr?.toString() ?? "";
|
|
7925
|
+
if (stderr) process.stderr.write(stderr);
|
|
7926
|
+
throw err;
|
|
7903
7927
|
} finally {
|
|
7904
7928
|
try {
|
|
7905
7929
|
(0, import_fs2.unlinkSync)(tmpFile);
|
|
@@ -7909,7 +7933,13 @@ function gitCommit(message) {
|
|
|
7909
7933
|
}
|
|
7910
7934
|
}
|
|
7911
7935
|
function gitPush() {
|
|
7912
|
-
|
|
7936
|
+
try {
|
|
7937
|
+
(0, import_child_process2.execFileSync)("git", ["push"], { stdio: "pipe" });
|
|
7938
|
+
} catch (err) {
|
|
7939
|
+
const stderr = err?.stderr?.toString() ?? "";
|
|
7940
|
+
if (stderr) process.stderr.write(stderr);
|
|
7941
|
+
throw err;
|
|
7942
|
+
}
|
|
7913
7943
|
}
|
|
7914
7944
|
function getBranchCommits(base = "main") {
|
|
7915
7945
|
validateRef(base, "base");
|
|
@@ -7979,6 +8009,12 @@ function getFullDiff(base = "main") {
|
|
|
7979
8009
|
maxBuffer: 10 * 1024 * 1024
|
|
7980
8010
|
});
|
|
7981
8011
|
}
|
|
8012
|
+
function getStagedFileCount() {
|
|
8013
|
+
const output = (0, import_child_process2.execFileSync)("git", ["diff", "--cached", "--name-only"], {
|
|
8014
|
+
encoding: "utf-8"
|
|
8015
|
+
});
|
|
8016
|
+
return output.trim().split("\n").filter(Boolean).length;
|
|
8017
|
+
}
|
|
7982
8018
|
function getStagedDiffShortstat() {
|
|
7983
8019
|
try {
|
|
7984
8020
|
const out = (0, import_child_process2.execFileSync)("git", ["diff", "--cached", "--shortstat"], {
|
|
@@ -7996,13 +8032,6 @@ function getStagedDiffShortstat() {
|
|
|
7996
8032
|
return { additions: 0, deletions: 0 };
|
|
7997
8033
|
}
|
|
7998
8034
|
}
|
|
7999
|
-
function getShortStagedFiles(max = 3) {
|
|
8000
|
-
const output = (0, import_child_process2.execFileSync)("git", ["diff", "--cached", "--name-only"], {
|
|
8001
|
-
encoding: "utf-8"
|
|
8002
|
-
});
|
|
8003
|
-
const all = output.trim().split("\n").filter(Boolean);
|
|
8004
|
-
return { files: all.slice(0, max), total: all.length };
|
|
8005
|
-
}
|
|
8006
8035
|
function getCommitHash() {
|
|
8007
8036
|
return (0, import_child_process2.execFileSync)("git", ["rev-parse", "--short", "HEAD"], {
|
|
8008
8037
|
encoding: "utf-8"
|
|
@@ -8135,7 +8164,13 @@ function getHeadSha() {
|
|
|
8135
8164
|
}
|
|
8136
8165
|
function gitPushSetUpstream(branch) {
|
|
8137
8166
|
validateRef(branch, "branch");
|
|
8138
|
-
|
|
8167
|
+
try {
|
|
8168
|
+
(0, import_child_process2.execFileSync)("git", ["push", "-u", "origin", branch], { stdio: "pipe" });
|
|
8169
|
+
} catch (err) {
|
|
8170
|
+
const stderr = err?.stderr?.toString() ?? "";
|
|
8171
|
+
if (stderr) process.stderr.write(stderr);
|
|
8172
|
+
throw err;
|
|
8173
|
+
}
|
|
8139
8174
|
}
|
|
8140
8175
|
function deleteBranch(name) {
|
|
8141
8176
|
validateRef(name, "name");
|
|
@@ -9362,7 +9397,7 @@ function renderBoxedCommit(header, body, opts) {
|
|
|
9362
9397
|
if (body) lines2.push("", body);
|
|
9363
9398
|
return lines2.join("\n");
|
|
9364
9399
|
}
|
|
9365
|
-
const innerWidth = opts.width -
|
|
9400
|
+
const innerWidth = opts.width - 6;
|
|
9366
9401
|
const horiz = opts.width - 2;
|
|
9367
9402
|
const top = " " + (opts.isColor ? import_picocolors2.default.dim("\u256D" + "\u2500".repeat(horiz) + "\u256E") : "\u256D" + "\u2500".repeat(horiz) + "\u256E");
|
|
9368
9403
|
const bottom = " " + (opts.isColor ? import_picocolors2.default.dim("\u2570" + "\u2500".repeat(horiz) + "\u256F") : "\u2570" + "\u2500".repeat(horiz) + "\u256F");
|
|
@@ -9380,7 +9415,7 @@ function renderBoxedCommit(header, body, opts) {
|
|
|
9380
9415
|
const lines = [];
|
|
9381
9416
|
const headerParts = wrapLine(firstLineStyled, innerWidth);
|
|
9382
9417
|
for (let i = 0; i < headerParts.length; i++) {
|
|
9383
|
-
const indent = i === 0 ? "" : "
|
|
9418
|
+
const indent = i === 0 ? "" : " ";
|
|
9384
9419
|
lines.push(boxedLine(indent + (headerParts[i] ?? ""), innerWidth, opts.isColor));
|
|
9385
9420
|
}
|
|
9386
9421
|
if (body) {
|
|
@@ -10112,8 +10147,17 @@ async function runLocalCommit(args) {
|
|
|
10112
10147
|
}
|
|
10113
10148
|
}
|
|
10114
10149
|
gitCommit(message);
|
|
10150
|
+
const branch = getCurrentBranch();
|
|
10151
|
+
log.step(`[${branch} committed]`);
|
|
10115
10152
|
if (args.push) {
|
|
10153
|
+
const pushStats = getPushStats();
|
|
10154
|
+
log.step(`pushing to origin/${branch}...`);
|
|
10116
10155
|
gitPush();
|
|
10156
|
+
if (pushStats) {
|
|
10157
|
+
log.success(`pushed ${pushStats.commits} commit(s) \xB7 ${pushStats.stat}`);
|
|
10158
|
+
} else {
|
|
10159
|
+
log.success("pushed");
|
|
10160
|
+
}
|
|
10117
10161
|
}
|
|
10118
10162
|
}
|
|
10119
10163
|
async function generateLocalBranchName(opts) {
|
|
@@ -10896,8 +10940,16 @@ async function runBranchGuard(args, log) {
|
|
|
10896
10940
|
if (action === "continue") {
|
|
10897
10941
|
return { action: "continue" };
|
|
10898
10942
|
}
|
|
10899
|
-
|
|
10900
|
-
|
|
10943
|
+
let stagedDiff = "";
|
|
10944
|
+
let stagedChanges = "";
|
|
10945
|
+
if (state.mode === "uncommitted") {
|
|
10946
|
+
stagedDiff = getStagedDiff(args.excludes ?? []);
|
|
10947
|
+
stagedChanges = getStagedFiles();
|
|
10948
|
+
if (!stagedDiff.trim()) {
|
|
10949
|
+
stagedDiff = getWorkingTreeDiff(args.excludes ?? []);
|
|
10950
|
+
stagedChanges = getAllChangedFiles();
|
|
10951
|
+
}
|
|
10952
|
+
}
|
|
10901
10953
|
const recentCommits = state.mode === "rescue" ? getRecentBranchCommits(state.commitsAhead) : void 0;
|
|
10902
10954
|
const branchRules = args.branchRules ?? (config2.branch?.generation?.types && config2.branch.generation.types.length > 0 ? { types: [...config2.branch.generation.types] } : void 0);
|
|
10903
10955
|
const apiKey = args.apiKey;
|
|
@@ -10990,10 +11042,22 @@ async function runBranchGuard(args, log) {
|
|
|
10990
11042
|
async function promptProtectedAction(mode) {
|
|
10991
11043
|
const rl = import_promises2.default.createInterface({ input: process.stdin, output: process.stderr });
|
|
10992
11044
|
try {
|
|
10993
|
-
const
|
|
10994
|
-
const
|
|
10995
|
-
|
|
10996
|
-
|
|
11045
|
+
const continueLabel = mode === "rescue" ? "commit on this branch anyway (do not move existing commits)" : "commit on this branch anyway (not recommended)";
|
|
11046
|
+
const branchLabel = mode === "rescue" ? "create a new branch and move your existing commits to it" : "create a new branch first, then commit your staged changes there";
|
|
11047
|
+
process.stderr.write(
|
|
11048
|
+
`
|
|
11049
|
+
What would you like to do?
|
|
11050
|
+
(b)ranch ${branchLabel} \u2190 default
|
|
11051
|
+
(c)ommit ${continueLabel}
|
|
11052
|
+
(a)bort cancel without committing
|
|
11053
|
+
`
|
|
11054
|
+
);
|
|
11055
|
+
const answer = (await rl.question("> ")).trim().toLowerCase();
|
|
11056
|
+
if (answer === "" || answer === "b" || answer === "branch" || answer === "y") return "branch";
|
|
11057
|
+
if (answer === "c" || answer === "commit") return "continue";
|
|
11058
|
+
if (answer === "a" || answer === "abort" || answer === "n") return "abort";
|
|
11059
|
+
process.stderr.write(`(unrecognized response "${answer}" \u2014 aborting)
|
|
11060
|
+
`);
|
|
10997
11061
|
return "abort";
|
|
10998
11062
|
} finally {
|
|
10999
11063
|
rl.close();
|
|
@@ -11051,15 +11115,13 @@ async function runCommit(args) {
|
|
|
11051
11115
|
void _exhaustive;
|
|
11052
11116
|
if (all || config2.autoStage) {
|
|
11053
11117
|
stageAll();
|
|
11054
|
-
const
|
|
11055
|
-
const fileList = total > 3 ? `${files.join(", ")}, +${total - 3} more` : files.join(", ");
|
|
11118
|
+
const total = getStagedFileCount();
|
|
11056
11119
|
log.step(`staging working tree (${total} file(s))...`);
|
|
11057
|
-
if (fileList) log.dim(` ${fileList}`);
|
|
11058
11120
|
}
|
|
11059
11121
|
if (!hasStagedChanges()) {
|
|
11060
11122
|
const unstaged = getUnstagedFiles();
|
|
11061
11123
|
if (unstaged.length > 0) {
|
|
11062
|
-
log.error("No staged changes. Use `qc -a` to stage
|
|
11124
|
+
log.error("No staged changes. Use `qc -a` to stage all files (modified + untracked), or `git add` manually.");
|
|
11063
11125
|
} else {
|
|
11064
11126
|
log.error("No changes to commit.");
|
|
11065
11127
|
}
|
|
@@ -11185,11 +11247,11 @@ async function runCommit(args) {
|
|
|
11185
11247
|
const branch = getCurrentBranch();
|
|
11186
11248
|
log.step(`[${branch} ${hash}] committed`);
|
|
11187
11249
|
if (push) {
|
|
11250
|
+
const pushStats = getPushStats();
|
|
11188
11251
|
log.step(`pushing to origin/${branch}...`);
|
|
11189
11252
|
gitPush();
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
log.success(`pushed ${stats.commits} commit(s) \xB7 ${stats.stat}`);
|
|
11253
|
+
if (pushStats) {
|
|
11254
|
+
log.success(`pushed ${pushStats.commits} commit(s) \xB7 ${pushStats.stat}`);
|
|
11193
11255
|
} else {
|
|
11194
11256
|
log.success("pushed");
|
|
11195
11257
|
}
|