watskeburt 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -35,9 +35,16 @@ console.log(getSHASync());
35
35
  /** @type {import('watskeburt').IChange[]} */
36
36
  const lChangedFiles = listSync("main");
37
37
 
38
- // As a second parameter you can pass some options:
38
+ // list all files that differ between 'v0.6.1' and 'v0.7.1' (by definition
39
+ // won't include files staged for commit and/ or not under revision control)
40
+ /** @type {import('watskeburt').IChange[]} */
41
+ const lChangedFiles = listSync("v0.6.1", "v0.7.1");
42
+
43
+ // As a third parameter you can pass some options
44
+ // (pass null as the second parameter if you only want to compare between
45
+ // a revision and the working tree):
39
46
  /** @type {import('watskeburt').IChange[]|string} */
40
- const lChangedFiles = listSync("main", {
47
+ const lChangedFiles = listSync("main", null, {
41
48
  trackedOnly: false, // when set to true leaves out files not under revision control
42
49
  outputType: "object", // other options: "json" and "regex" (as used in the CLI)
43
50
  });
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},A=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of E(t))!x.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(o=y(t,r))||o.enumerable});return e};var _=e=>A(a({},"__esModule",{value:!0}),e);var k={};C(k,{getSHASync:()=>j,listSync:()=>I});module.exports=_(k);var u=require("os"),D=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,R=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,L={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function i(e){return L[e]||"unknown"}function v(e){let t=e.match(R),n={};if(t){let o=i(t.groups.stagedChangeType),r=i(t.groups.unStagedChangeType);n.changeType=o==="unmodified"?r:o,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function O(e){let t=e.match(D),n={};return t&&(n.changeType=i(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function m(e){return e.split(u.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}function d(e){return e.split(u.EOL).filter(Boolean).map(O).filter(({changeType:t})=>Boolean(t))}var s=require("child_process");function T(e){return e instanceof Buffer?e.toString("utf8"):e}function U(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let o=n("git",e,{cwd:process.cwd(),env:process.env});if(o.error&&U(o.error),o.status===0)return T(o.stdout);throw new Error(t[o.status]||`internal git error: ${o.status} (${T(o.stderr)})`)}function S(e=s.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=s.spawnSync){let n={128:`revision '${e}' unknown `,129:`'${process.cwd()}' does not seem to be a git repository`};return c(["diff",e,"--name-status"],n,t)}function f(e=s.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path"),M=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),$=new Set(["modified","added","renamed","copied","untracked"]);function p(e,t=M,n=$){return`^(${e.filter(r=>n.has(r.changeType)).map(({name:r})=>r).filter(r=>t.has((0,N.extname)(r))).join("|")})$`}function l(e){return JSON.stringify(e,null,2)}var B=e=>e,H=new Map([["regex",p],["json",l]]);function g(e,t){return(H.get(t)||B)(e)}function j(){return f()}function I(e,t){let n=e||f(),o=d(h(n)),r=t||{};return r.trackedOnly||(o=o.concat(m(S()).filter(({changeType:w})=>w==="untracked"))),g(o,r.outputType)}0&&(module.exports={getSHASync,listSync});
1
+ "use strict";var i=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var _=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},D=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of C(t))!A.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=x(t,o))||r.enumerable});return e};var L=e=>D(i({},"__esModule",{value:!0}),e);var P={};_(P,{getSHASync:()=>k,listSync:()=>F});module.exports=L(P);var c=require("os"),R=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,O=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,U={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function u(e){return U[e]||"unknown"}function $(e){let t=e.match(O),n={};if(t){let r=u(t.groups.stagedChangeType),o=u(t.groups.unStagedChangeType);n.changeType=r==="unmodified"?o:r,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function v(e){let t=e.match(R),n={};return t&&(n.changeType=u(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function T(e){return e.split(c.EOL).filter(Boolean).map($).filter(({changeType:t})=>Boolean(t))}function S(e){return e.split(c.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}var a=require("child_process");function h(e){return e instanceof Buffer?e.toString("utf8"):e}function M(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function f(e,t,n){let r=n("git",e,{cwd:process.cwd(),env:process.env});if(r.error&&M(r.error),r.status===0)return h(r.stdout);throw new Error(t[r.status]||`internal git error: ${r.status} (${h(r.stderr)})`)}function N(e=a.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return f(["status","--porcelain"],t,e)}function y(e,t,n=a.spawnSync){let r={128:`revision '${e}' ${t?`(or '${t}') `:""}unknown`,129:`'${process.cwd()}' does not seem to be a git repository`};return f(t?["diff",e,t,"--name-status"]:["diff",e,"--name-status"],r,n)}function l(e=a.spawnSync){return f(["rev-parse","HEAD"],{},e).slice(0,40)}var E=require("path"),B=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),H=new Set(["modified","added","renamed","copied","untracked"]);function p(e,t=B,n=H){return`^(${e.filter(o=>n.has(o.changeType)).map(({name:o})=>o).filter(o=>t.has((0,E.extname)(o))).join("|")})$`}function m(e){return JSON.stringify(e,null,2)}var j=e=>e,I=new Map([["regex",p],["json",m]]);function g(e,t){return(I.get(t)||j)(e)}function k(){return l()}function F(e,t,n){let r=e||l(),o=t||null,d=n||{},s=S(y(r,o));return d.trackedOnly||(s=s.concat(T(N()).filter(({changeType:w})=>w==="untracked"))),g(s,d.outputType)}0&&(module.exports={getSHASync,listSync});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watskeburt",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "List files changed since a git revision",
5
5
  "keywords": [
6
6
  "git",
package/src/cli.mjs CHANGED
@@ -7,17 +7,19 @@ import { VERSION } from "./version.mjs";
7
7
 
8
8
  program
9
9
  .description(
10
- "lists files & their statuses since [revision].\n\n" +
11
- "-> When you don't pass a revision the revision defaults to the current one."
10
+ "lists files & their statuses since [old-revision] " +
11
+ "or between [old-revision] and [new-revision]." +
12
+ "\n\n" +
13
+ "-> When you don't pass a revision at all old-revision defaults to the current one."
12
14
  )
13
15
  .version(VERSION)
14
16
  .option("-T, --output-type <type>", "json,regex", "regex")
15
17
  .option("--tracked-only", "only take tracked files into account", false)
16
- .arguments("[revision]")
18
+ .arguments("[old-revision] [new-revision]")
17
19
  .parse(process.argv);
18
20
 
19
21
  try {
20
- console.log(listSync(program.args[0], program.opts()));
22
+ console.log(listSync(program.args[0], program.args[1], program.opts()));
21
23
  } catch (pError) {
22
24
  console.error(`ERROR: ${pError.message}`);
23
25
  }
@@ -60,16 +60,27 @@ export function getStatusShort(pSpawnFunction = spawnSync) {
60
60
  /**
61
61
  *
62
62
  * @param {string} pOldRevision the target to compare against (e.g. branch name, commit, tag etc)
63
+ * @param {string} pNewRevision Newer revision against which to compare. Leave out or pass
64
+ * null when you want to compare against the working tree
63
65
  * @return {string}
64
66
  * @throws {Error}
65
67
  */
66
- export function getDiffLines(pOldRevision, pSpawnFunction = spawnSync) {
68
+ export function getDiffLines(
69
+ pOldRevision,
70
+ pNewRevision,
71
+ pSpawnFunction = spawnSync
72
+ ) {
67
73
  const lErrorMap = {
68
- 128: `revision '${pOldRevision}' unknown `,
74
+ 128: `revision '${pOldRevision}' ${
75
+ pNewRevision ? `(or '${pNewRevision}') ` : ""
76
+ }unknown`,
69
77
  129: `'${process.cwd()}' does not seem to be a git repository`,
70
78
  };
79
+
71
80
  return getGitResult(
72
- ["diff", pOldRevision, "--name-status"],
81
+ pNewRevision
82
+ ? ["diff", pOldRevision, pNewRevision, "--name-status"]
83
+ : ["diff", pOldRevision, "--name-status"],
73
84
  lErrorMap,
74
85
  pSpawnFunction
75
86
  );
package/src/main.mjs CHANGED
@@ -11,11 +11,13 @@ export function getSHASync() {
11
11
  }
12
12
 
13
13
  /** @type {import("../types/watskeburt").listSync} */
14
- export function listSync(pOldRevision, pOptions) {
14
+ export function listSync(pOldRevision, pNewRevision, pOptions) {
15
15
  const lOldRevision = pOldRevision || getSHA1();
16
- let lChanges = convertDiffLines(getDiffLines(lOldRevision));
16
+ const lNewRevision = pNewRevision || null;
17
17
  const lOptions = pOptions || {};
18
18
 
19
+ let lChanges = convertDiffLines(getDiffLines(lOldRevision, lNewRevision));
20
+
19
21
  if (!lOptions.trackedOnly) {
20
22
  lChanges = lChanges.concat(
21
23
  convertStatusLines(getStatusShort()).filter(
package/src/version.mjs CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.6.1";
1
+ export const VERSION = "0.7.0";
@@ -50,12 +50,15 @@ export interface IOptions {
50
50
  * @param pOldRevision The revision against which to compare. E.g. a commit-hash,
51
51
  * a branch or a tag. When not passed defaults to the _current_
52
52
  * commit hash (if there's any)
53
+ * @param pNewRevision Newer revision against which to compare. Leave out or pass
54
+ * null when you want to compare against the working tree
53
55
  * @param pOptions Options that influence how the changes are returned and that
54
56
  * filter what is returned and
55
57
  * @throws {Error}
56
58
  */
57
59
  export function listSync(
58
60
  pOldRevision?: string,
61
+ pNewRevision?: string,
59
62
  pOptions?: IOptions
60
63
  ): IChange[] | string;
61
64