contribute-now 0.3.0 → 0.4.0-dev.ba6545c
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 +41 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { defineCommand } from "citty";
|
|
|
10
10
|
import pc2 from "picocolors";
|
|
11
11
|
|
|
12
12
|
// src/utils/config.ts
|
|
13
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
var CONFIG_FILENAME = ".contributerc.json";
|
|
16
16
|
function getConfigPath(cwd = process.cwd()) {
|
|
@@ -86,6 +86,23 @@ function isGitignored(cwd = process.cwd()) {
|
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
function ensureGitignored(cwd = process.cwd()) {
|
|
90
|
+
if (isGitignored(cwd))
|
|
91
|
+
return false;
|
|
92
|
+
const gitignorePath = join(cwd, ".gitignore");
|
|
93
|
+
const line = `${CONFIG_FILENAME}
|
|
94
|
+
`;
|
|
95
|
+
if (!existsSync(gitignorePath)) {
|
|
96
|
+
writeFileSync(gitignorePath, line, "utf-8");
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const content = readFileSync(gitignorePath, "utf-8");
|
|
100
|
+
const needsLeadingNewline = content.length > 0 && !content.endsWith(`
|
|
101
|
+
`);
|
|
102
|
+
appendFileSync(gitignorePath, `${needsLeadingNewline ? `
|
|
103
|
+
` : ""}${line}`, "utf-8");
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
89
106
|
function getDefaultConfig() {
|
|
90
107
|
return {
|
|
91
108
|
workflow: "clean-flow",
|
|
@@ -205,6 +222,13 @@ async function branchExists(branch) {
|
|
|
205
222
|
const { exitCode } = await run(["rev-parse", "--verify", branch]);
|
|
206
223
|
return exitCode === 0;
|
|
207
224
|
}
|
|
225
|
+
async function countCommitsAhead(branch, upstream) {
|
|
226
|
+
const { exitCode, stdout } = await run(["rev-list", "--count", `${upstream}..${branch}`]);
|
|
227
|
+
if (exitCode !== 0)
|
|
228
|
+
return 0;
|
|
229
|
+
const count = Number.parseInt(stdout.trim(), 10);
|
|
230
|
+
return Number.isNaN(count) ? 0 : count;
|
|
231
|
+
}
|
|
208
232
|
async function fetchRemote(remote) {
|
|
209
233
|
return run(["fetch", remote]);
|
|
210
234
|
}
|
|
@@ -1994,7 +2018,7 @@ import pc7 from "picocolors";
|
|
|
1994
2018
|
// package.json
|
|
1995
2019
|
var package_default = {
|
|
1996
2020
|
name: "contribute-now",
|
|
1997
|
-
version: "0.
|
|
2021
|
+
version: "0.4.0-dev.ba6545c",
|
|
1998
2022
|
description: "Git workflow CLI for squash-merge two-branch models. Keeps dev in sync with main after squash merges.",
|
|
1999
2023
|
type: "module",
|
|
2000
2024
|
bin: {
|
|
@@ -2792,9 +2816,8 @@ var setup_default = defineCommand7({
|
|
|
2792
2816
|
warn("Config was saved — verify the branch name and re-run setup if needed.");
|
|
2793
2817
|
}
|
|
2794
2818
|
}
|
|
2795
|
-
if (
|
|
2796
|
-
|
|
2797
|
-
warn(' echo ".contributerc.json" >> .gitignore');
|
|
2819
|
+
if (ensureGitignored()) {
|
|
2820
|
+
info("Added .contributerc.json to .gitignore to avoid committing personal config.");
|
|
2798
2821
|
}
|
|
2799
2822
|
console.log();
|
|
2800
2823
|
info(`Workflow: ${pc10.bold(WORKFLOW_DESCRIPTIONS[config.workflow])}`);
|
|
@@ -2897,6 +2920,19 @@ var start_default = defineCommand8({
|
|
|
2897
2920
|
if (!await refExists(syncSource.ref)) {
|
|
2898
2921
|
warn(`Remote ref ${pc11.bold(syncSource.ref)} not found. Creating branch from local ${pc11.bold(baseBranch)}.`);
|
|
2899
2922
|
}
|
|
2923
|
+
const currentBranch = await getCurrentBranch();
|
|
2924
|
+
if (currentBranch === baseBranch && await refExists(syncSource.ref)) {
|
|
2925
|
+
const ahead = await countCommitsAhead(baseBranch, syncSource.ref);
|
|
2926
|
+
if (ahead > 0) {
|
|
2927
|
+
warn(`You are on ${pc11.bold(baseBranch)} with ${pc11.bold(String(ahead))} local commit${ahead > 1 ? "s" : ""} not in ${pc11.bold(syncSource.ref)}.`);
|
|
2928
|
+
info(" Syncing will discard those commits. Consider backing them up first (e.g. create a branch).");
|
|
2929
|
+
const proceed = await confirmPrompt("Discard local commits and sync to remote?");
|
|
2930
|
+
if (!proceed) {
|
|
2931
|
+
info("Aborted. Your local commits are untouched.");
|
|
2932
|
+
process.exit(0);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2900
2936
|
const updateResult = await updateLocalBranch(baseBranch, syncSource.ref);
|
|
2901
2937
|
if (updateResult.exitCode !== 0) {
|
|
2902
2938
|
if (await refExists(syncSource.ref)) {
|