@jannael/glinter 1.2.9 → 1.3.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 +129 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -116,6 +116,11 @@ var AVAILABLE_COMMANDS = [
|
|
|
116
116
|
name: "setup",
|
|
117
117
|
command: "g setup",
|
|
118
118
|
description: "Setup alias for git and glinter"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "reset-hard",
|
|
122
|
+
command: "g reset-hard",
|
|
123
|
+
description: "Interactive reset hard"
|
|
119
124
|
}
|
|
120
125
|
];
|
|
121
126
|
|
|
@@ -1854,8 +1859,6 @@ class AddCommand {
|
|
|
1854
1859
|
const options = changes.map((c3) => ({ value: c3.value, label: c3.label }));
|
|
1855
1860
|
const selectedChanges = await MultiSelect({
|
|
1856
1861
|
message: `Select the changes you want to commit.
|
|
1857
|
-
` + BLUE({ text: "[space] to select" }) + `
|
|
1858
|
-
` + GREEN({ text: "[enter] to confirm" }) + `
|
|
1859
1862
|
` + MAGENTA({ text: "[a] to select all" }) + `
|
|
1860
1863
|
` + RED({ text: "[esc] to cancel" }) + `
|
|
1861
1864
|
`,
|
|
@@ -2055,7 +2058,9 @@ var ALIASES = [
|
|
|
2055
2058
|
{ name: "gstp", command: "stash pop", kind: "git" },
|
|
2056
2059
|
{ name: "gstl", command: "stash list", kind: "git" },
|
|
2057
2060
|
{ name: "gcl", command: "clean -fd", kind: "git" },
|
|
2058
|
-
{ name: "grh", command: "reset --hard", kind: "git" }
|
|
2061
|
+
{ name: "grh", command: "reset --hard", kind: "git" },
|
|
2062
|
+
{ name: "ggrh", command: "reset-hard", kind: "glinter" },
|
|
2063
|
+
{ name: "ggclean", command: "reset --hard && git clean -fd", kind: "git" }
|
|
2059
2064
|
];
|
|
2060
2065
|
|
|
2061
2066
|
// apps/cli/modules/alias/main.ts
|
|
@@ -2203,6 +2208,123 @@ async function commitCommand() {
|
|
|
2203
2208
|
await commitCmd.execute();
|
|
2204
2209
|
}
|
|
2205
2210
|
|
|
2211
|
+
// apps/cli/modules/reset-hard/app/reset-hard-command.ts
|
|
2212
|
+
var PREV_PAGE = "< Previous page";
|
|
2213
|
+
var NEXT_PAGE = "Next page >";
|
|
2214
|
+
|
|
2215
|
+
class ResetHardCommand {
|
|
2216
|
+
resetHardRepository;
|
|
2217
|
+
constructor(resetHardRepository) {
|
|
2218
|
+
this.resetHardRepository = resetHardRepository;
|
|
2219
|
+
}
|
|
2220
|
+
async execute() {
|
|
2221
|
+
try {
|
|
2222
|
+
let page = 0;
|
|
2223
|
+
const pageSize = 10;
|
|
2224
|
+
while (true) {
|
|
2225
|
+
const { commits, hasMore } = await this.resetHardRepository.getCommits(page, pageSize);
|
|
2226
|
+
if (commits.length === 0) {
|
|
2227
|
+
console.log(`${WARNING({ text: "No commits found." })}`);
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
const options = [];
|
|
2231
|
+
if (page > 0) {
|
|
2232
|
+
options.push({ value: PREV_PAGE, label: PREV_PAGE });
|
|
2233
|
+
}
|
|
2234
|
+
for (const commit of commits) {
|
|
2235
|
+
options.push({
|
|
2236
|
+
value: commit.hash,
|
|
2237
|
+
label: `${YELLOW({ text: commit.shortHash })} ${commit.subject}`
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
if (hasMore) {
|
|
2241
|
+
options.push({ value: NEXT_PAGE, label: NEXT_PAGE });
|
|
2242
|
+
}
|
|
2243
|
+
const selected = await Select({
|
|
2244
|
+
message: "Select the commit you want to reset to.",
|
|
2245
|
+
options
|
|
2246
|
+
});
|
|
2247
|
+
if (selected === PREV_PAGE) {
|
|
2248
|
+
page -= 1;
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
if (selected === NEXT_PAGE) {
|
|
2252
|
+
page += 1;
|
|
2253
|
+
continue;
|
|
2254
|
+
}
|
|
2255
|
+
await this.resetHardRepository.resetHard(selected);
|
|
2256
|
+
console.log(`${CHECK({ text: "Successfully reset to " + selected })}`);
|
|
2257
|
+
break;
|
|
2258
|
+
}
|
|
2259
|
+
} catch (error) {
|
|
2260
|
+
errorHandler(error);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
// apps/cli/modules/reset-hard/infra/bun-reset-hard.repository.ts
|
|
2266
|
+
var {$: $2 } = globalThis.Bun;
|
|
2267
|
+
|
|
2268
|
+
// apps/cli/modules/reset-hard/domain/commit.ts
|
|
2269
|
+
class Commit {
|
|
2270
|
+
props;
|
|
2271
|
+
constructor(props) {
|
|
2272
|
+
this.props = props;
|
|
2273
|
+
}
|
|
2274
|
+
get hash() {
|
|
2275
|
+
return this.props.hash;
|
|
2276
|
+
}
|
|
2277
|
+
get shortHash() {
|
|
2278
|
+
return this.props.hash.slice(0, 7);
|
|
2279
|
+
}
|
|
2280
|
+
get subject() {
|
|
2281
|
+
return this.props.subject;
|
|
2282
|
+
}
|
|
2283
|
+
static fromGitLog(output) {
|
|
2284
|
+
if (!output.trim())
|
|
2285
|
+
return [];
|
|
2286
|
+
const lines = output.split(`
|
|
2287
|
+
`).filter((line) => line.trim() !== "");
|
|
2288
|
+
return lines.map((line) => {
|
|
2289
|
+
const hash = line.substring(0, 40);
|
|
2290
|
+
const subject = line.substring(41).trim();
|
|
2291
|
+
return new Commit({ hash, subject });
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
// apps/cli/modules/reset-hard/infra/bun-reset-hard.repository.ts
|
|
2297
|
+
class BunResetHardRepository {
|
|
2298
|
+
async getCommits(page, pageSize) {
|
|
2299
|
+
try {
|
|
2300
|
+
const skip = page * pageSize;
|
|
2301
|
+
const output = await $2`git --no-pager log -n ${pageSize + 1} --skip=${skip} --format="%H %s"`.quiet().text();
|
|
2302
|
+
const allCommits = Commit.fromGitLog(output);
|
|
2303
|
+
const hasMore = allCommits.length > pageSize;
|
|
2304
|
+
const commits = hasMore ? allCommits.slice(0, pageSize) : allCommits;
|
|
2305
|
+
return { commits, hasMore };
|
|
2306
|
+
} catch {
|
|
2307
|
+
throw new ServerError("Git log failed", "Could not retrieve commits");
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
async resetHard(hash) {
|
|
2311
|
+
const proc = Bun.spawn(["git", "reset", "--hard", hash], {
|
|
2312
|
+
stdio: ["inherit", "inherit", "inherit"]
|
|
2313
|
+
});
|
|
2314
|
+
const exitCode = await proc.exited;
|
|
2315
|
+
if (exitCode !== 0) {
|
|
2316
|
+
throw new ServerError("Git reset failed", `Failed to reset to commit ${hash}`);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
// apps/cli/modules/reset-hard/main.ts
|
|
2322
|
+
async function resetHardCommand() {
|
|
2323
|
+
const resetHardRepository = new BunResetHardRepository;
|
|
2324
|
+
const resetHardCmd = new ResetHardCommand(resetHardRepository);
|
|
2325
|
+
await resetHardCmd.execute();
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2206
2328
|
// apps/cli/modules/setup/app/setup-aliases.use-case.ts
|
|
2207
2329
|
class SetupAliasesUseCase {
|
|
2208
2330
|
aliasRepository;
|
|
@@ -2520,11 +2642,11 @@ class SwitchCommand {
|
|
|
2520
2642
|
}
|
|
2521
2643
|
|
|
2522
2644
|
// apps/cli/modules/switch/infra/bun-switch-repository.ts
|
|
2523
|
-
var {$: $
|
|
2645
|
+
var {$: $3 } = globalThis.Bun;
|
|
2524
2646
|
class BunSwitchRepository {
|
|
2525
2647
|
async getBranches() {
|
|
2526
2648
|
try {
|
|
2527
|
-
const output = await $
|
|
2649
|
+
const output = await $3`git branch -a`.quiet().text();
|
|
2528
2650
|
if (!output.trim()) {
|
|
2529
2651
|
return [];
|
|
2530
2652
|
}
|
|
@@ -2560,7 +2682,8 @@ var COMMANDS_FN = {
|
|
|
2560
2682
|
commit: commitCommand,
|
|
2561
2683
|
switch: switchCommand,
|
|
2562
2684
|
alias: aliasCommand,
|
|
2563
|
-
setup: setupCommand
|
|
2685
|
+
setup: setupCommand,
|
|
2686
|
+
"reset-hard": resetHardCommand
|
|
2564
2687
|
};
|
|
2565
2688
|
|
|
2566
2689
|
// apps/cli/index.ts
|