diffity 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/index.js +14 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import open from "open";
11
11
  import pc2 from "picocolors";
12
12
 
13
13
  // ../git/dist/repo.js
14
- import { execSync as execSync2 } from "node:child_process";
14
+ import { execFileSync, execSync as execSync2 } from "node:child_process";
15
15
  import { createHash } from "node:crypto";
16
16
  import { mkdirSync } from "node:fs";
17
17
  import { join } from "node:path";
@@ -87,6 +87,17 @@ function getDiffityDir() {
87
87
  let dir = getDiffityDirPath();
88
88
  return mkdirSync(dir, { recursive: !0 }), dir;
89
89
  }
90
+ function isValidGitRef(ref) {
91
+ if (ref.includes("..."))
92
+ return ref.split("...").every((p) => isValidGitRef(p));
93
+ if (ref.includes(".."))
94
+ return ref.split("..").every((p) => isValidGitRef(p));
95
+ try {
96
+ return execFileSync("git", ["rev-parse", "--verify", ref], { stdio: "pipe" }), !0;
97
+ } catch {
98
+ return !1;
99
+ }
100
+ }
90
101
  var ACTIONABLE_REFS = /* @__PURE__ */ new Set(["work", "staged", "unstaged", "working", "untracked"]);
91
102
  function isActionableRef(ref) {
92
103
  return !!ref && ACTIONABLE_REFS.has(ref);
@@ -1019,6 +1030,8 @@ Examples:
1019
1030
  $ diffity main feature Same as main..feature
1020
1031
  $ diffity v1.0.0..v2.0.0 Compare tags`).action(async (refs, opts) => {
1021
1032
  isGitRepo() || (console.error(pc2.red("Error: Not a git repository")), process.exit(1));
1033
+ for (let ref of refs)
1034
+ isValidGitRef(ref) || (console.error(pc2.red(`Error: '${ref}' is not a valid git reference.`)), console.log(""), console.log("Usage:"), console.log(` ${pc2.cyan("diffity")} Working tree changes`), console.log(` ${pc2.cyan("diffity HEAD~1")} Last commit vs working tree`), console.log(` ${pc2.cyan("diffity main..feature")} Compare branches`), console.log(` ${pc2.cyan("diffity main feature")} Same as main..feature`), console.log(""), console.log(`Run ${pc2.cyan("diffity --help")} for more options.`), process.exit(1));
1022
1035
  let diffArgs = [], description = "";
1023
1036
  if (refs.length === 1) {
1024
1037
  let ref = refs[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diffity",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "GitHub-style git diff viewer in the browser",
5
5
  "type": "module",
6
6
  "bin": {