gnhf 0.1.4 → 0.1.5

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/README.md CHANGED
@@ -53,6 +53,8 @@ $ gnhf "reduce complexity of the codebase without changing functionality"
53
53
  # go to sleep
54
54
  ```
55
55
 
56
+ Run `gnhf` from inside a Git repository with a clean working tree. If you are starting from a plain directory, run `git init` first.
57
+
56
58
  ## Install
57
59
 
58
60
  **npm**
package/dist/cli.mjs CHANGED
@@ -50,15 +50,47 @@ function loadConfig(overrides) {
50
50
  }
51
51
  //#endregion
52
52
  //#region src/core/git.ts
53
+ const NOT_GIT_REPOSITORY_MESSAGE = "This command must be run inside a Git repository. Change into a repo or run \"git init\" first.";
54
+ function translateGitError(error) {
55
+ return error instanceof Error ? error : new Error(String(error));
56
+ }
53
57
  function git(args, cwd) {
54
- return execSync(`git ${args}`, {
55
- cwd,
56
- encoding: "utf-8",
57
- stdio: "pipe"
58
- }).trim();
58
+ try {
59
+ return execSync(`git ${args}`, {
60
+ cwd,
61
+ encoding: "utf-8",
62
+ stdio: "pipe"
63
+ }).trim();
64
+ } catch (error) {
65
+ throw translateGitError(error);
66
+ }
67
+ }
68
+ function isGitRepository(cwd) {
69
+ try {
70
+ execSync("git rev-parse --git-dir", {
71
+ cwd,
72
+ encoding: "utf-8",
73
+ stdio: "pipe",
74
+ env: {
75
+ ...process.env,
76
+ LC_ALL: "C"
77
+ }
78
+ });
79
+ return true;
80
+ } catch {
81
+ return false;
82
+ }
83
+ }
84
+ function ensureGitRepository(cwd) {
85
+ if (!isGitRepository(cwd)) throw new Error(NOT_GIT_REPOSITORY_MESSAGE);
59
86
  }
60
87
  function getCurrentBranch(cwd) {
61
- return git("rev-parse --abbrev-ref HEAD", cwd);
88
+ ensureGitRepository(cwd);
89
+ try {
90
+ return git("symbolic-ref --short HEAD", cwd);
91
+ } catch {
92
+ return git("rev-parse --abbrev-ref HEAD", cwd);
93
+ }
62
94
  }
63
95
  function ensureCleanWorkingTree(cwd) {
64
96
  if (git("status --porcelain", cwd)) throw new Error("Working tree is not clean. Commit or stash changes first.");
@@ -1199,6 +1231,10 @@ function slugifyPrompt(prompt) {
1199
1231
  //#endregion
1200
1232
  //#region src/cli.ts
1201
1233
  const packageVersion = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8")).version;
1234
+ function humanizeErrorMessage(message) {
1235
+ if (message.includes("not a git repository")) return "This command must be run inside a Git repository. Change into a repo or run \"git init\" first.";
1236
+ return message;
1237
+ }
1202
1238
  function initializeNewBranch(prompt, cwd) {
1203
1239
  ensureCleanWorkingTree(cwd);
1204
1240
  const baseCommit = getHeadCommit(cwd);
@@ -1292,7 +1328,7 @@ function exitAltScreen() {
1292
1328
  process$1.stdout.write("\x1B[?1049l");
1293
1329
  }
1294
1330
  function die(message) {
1295
- console.error(`\n gnhf: ${message}\n`);
1331
+ console.error(`\n gnhf: ${humanizeErrorMessage(message)}\n`);
1296
1332
  process$1.exit(1);
1297
1333
  }
1298
1334
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gnhf",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Before I go to bed, I tell my agents: good night, have fun",
5
5
  "type": "module",
6
6
  "bin": {