guito 0.5.3 → 0.6.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.
@@ -0,0 +1 @@
1
+ function h(a){let n=[],i=new Int32Array(a.length),l=r=>{let t=n.indexOf(r);return t===-1&&(t=n.indexOf(null),t===-1&&(n.push(null),t=n.length-1),n[t]=r),t};for(let r=0;r<a.length;r++){let{hash:t,parents:o}=a[r],s=n.map((e,c)=>e===t?c:-1).filter(e=>e!==-1),p;if(s.length>0){p=s[0];for(let e=1;e<s.length;e++)n[s[e]]=null}else p=l(t);n[p]=o[0]??null;for(let e=1;e<o.length;e++)l(o[e]);i[r]=p}return i}addEventListener("message",a=>{let{id:n,hashes:i,parents:l}=a.data,r=h(i.map((o,s)=>({hash:o,parents:l[s]??[]})));postMessage({id:n,lanes:r},[r.buffer])});
@@ -0,0 +1,141 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { isAbsolute, join, relative, resolve, sep } from 'node:path';
3
+ /** NUL-delimited metadata is authoritative: patch headers quote unusual filenames. */
4
+ function names(raw) {
5
+ const fields = raw.split('\0');
6
+ const result = [];
7
+ for (let i = 0; fields[i];) {
8
+ const code = fields[i++];
9
+ const first = fields[i++];
10
+ const renamed = /^[RC]/.test(code);
11
+ result.push({ code, path: renamed ? fields[i++] : first, oldPath: first });
12
+ }
13
+ return result;
14
+ }
15
+ export function workingTree(git, parse) {
16
+ const hasHead = async () => {
17
+ try {
18
+ await git.raw(['rev-parse', '--verify', 'HEAD']);
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ };
25
+ async function changes(args) {
26
+ const common = ['diff', '--no-ext-diff', '--no-textconv', '--no-color', '--find-renames', '--diff-filter=ACDMRT', ...args];
27
+ const metadata = names(await git.raw([...common, '--name-status', '-z']));
28
+ const patches = parse(await git.raw([...common, '--patch']));
29
+ return metadata.map((entry, index) => ({
30
+ lines: [], additions: 0, deletions: 0, ...patches[index],
31
+ path: entry.path,
32
+ oldPath: entry.code[0] === 'A' ? '' : entry.oldPath,
33
+ status: patches[index]?.status === 'binary' ? 'binary' :
34
+ ({ A: 'added', D: 'deleted', R: 'renamed' }[entry.code[0]] ?? 'modified'),
35
+ }));
36
+ }
37
+ async function status() {
38
+ const fields = (await git.raw(['status', '--porcelain=v1', '-z', '--untracked-files=all'])).split('\0');
39
+ const entries = [];
40
+ for (let i = 0; fields[i];) {
41
+ const field = fields[i++];
42
+ const index = field[0], working = field[1], path = field.slice(3);
43
+ const oldPath = /[RC]/.test(index + working) ? fields[i++] : '';
44
+ entries.push({ path, oldPath, index, working });
45
+ }
46
+ return entries;
47
+ }
48
+ async function untrackedDiff(root, path) {
49
+ const buffer = await readFile(join(root, path));
50
+ const binary = buffer.includes(0);
51
+ const text = buffer.toString('utf8');
52
+ const lines = text ? text.replace(/\n$/, '').split('\n') : [];
53
+ return {
54
+ path, oldPath: '', status: binary ? 'binary' : 'added',
55
+ lines: binary ? [] : lines.map((text, i) => ({ type: 'add', newLine: i + 1, text })),
56
+ additions: binary ? 0 : lines.length, deletions: 0,
57
+ };
58
+ }
59
+ async function snapshot() {
60
+ const root = (await git.revparse(['--show-toplevel'])).trim();
61
+ const entries = await status();
62
+ const stagedFiles = await changes(['--cached']);
63
+ const unstagedFiles = await changes([]);
64
+ const untracked = entries.filter(e => e.index === '?').map(e => e.path);
65
+ const conflicted = entries.filter(e => e.index === 'U' || e.working === 'U' || ['AA', 'DD'].includes(e.index + e.working)).map(e => e.path);
66
+ for (const path of untracked)
67
+ unstagedFiles.push(await untrackedDiff(root, path));
68
+ for (const path of conflicted) {
69
+ if (!unstagedFiles.some(file => file.path === path)) {
70
+ unstagedFiles.push({ path, oldPath: path, status: 'modified', lines: [], additions: 0, deletions: 0 });
71
+ }
72
+ }
73
+ const combined = await hasHead() ? await changes(['HEAD']) : [...stagedFiles];
74
+ const files = new Map(combined.map(file => [file.path, file]));
75
+ // The combined diff can be empty even when index and working changes cancel.
76
+ for (const file of [...stagedFiles, ...unstagedFiles])
77
+ if (!files.has(file.path))
78
+ files.set(file.path, file);
79
+ return {
80
+ files: [...files.values()], stagedFiles, unstagedFiles, conflicted,
81
+ staged: stagedFiles.map(file => file.path),
82
+ unstaged: unstagedFiles.filter(file => !untracked.includes(file.path)).map(file => file.path),
83
+ untracked,
84
+ };
85
+ }
86
+ async function validate(files) {
87
+ if (!Array.isArray(files) || !files.length || files.some(file => typeof file !== 'string' || !file)) {
88
+ throw new Error('Select at least one file.');
89
+ }
90
+ const root = (await git.revparse(['--show-toplevel'])).trim();
91
+ for (const file of files) {
92
+ const rel = relative(root, resolve(root, file));
93
+ if (file.includes('\0') || isAbsolute(file) || !rel || rel === '..' || rel.startsWith(`..${sep}`) ||
94
+ isAbsolute(rel) || file.split(/[\\/]/).some((part) => part === '..' || part.toLowerCase() === '.git')) {
95
+ throw new Error('Select repository-relative file paths.');
96
+ }
97
+ }
98
+ return [...new Set(files)];
99
+ }
100
+ async function stage(files) {
101
+ const selected = await validate(files);
102
+ const entries = await status();
103
+ const paths = new Set();
104
+ for (const path of selected) {
105
+ const entry = entries.find(e => e.path === path);
106
+ if (!entry)
107
+ throw new Error(`File is no longer changed: ${path}`);
108
+ paths.add(path);
109
+ if (entry.oldPath && /[RC]/.test(entry.working))
110
+ paths.add(entry.oldPath);
111
+ }
112
+ await git.raw(['--literal-pathspecs', 'add', '-A', '--', ...paths]);
113
+ }
114
+ async function unstage(files) {
115
+ const selected = await validate(files);
116
+ const entries = names(await git.raw(['diff', '--cached', '--name-status', '--find-renames', '-z']));
117
+ const paths = new Set();
118
+ for (const path of selected) {
119
+ const entry = entries.find(e => e.path === path);
120
+ if (!entry)
121
+ throw new Error(`File is no longer staged: ${path}`);
122
+ paths.add(path);
123
+ paths.add(entry.oldPath);
124
+ }
125
+ await git.raw(await hasHead()
126
+ ? ['--literal-pathspecs', 'reset', '-q', 'HEAD', '--', ...paths]
127
+ : ['--literal-pathspecs', 'rm', '--cached', '-f', '--ignore-unmatch', '--', ...paths]);
128
+ }
129
+ async function commit(message, description) {
130
+ if (typeof message !== 'string' || !message.trim() || /[\r\n\0]/.test(message))
131
+ throw new Error('Enter a commit subject on one line.');
132
+ if (description !== undefined && (typeof description !== 'string' || description.includes('\0')))
133
+ throw new Error('Invalid commit description.');
134
+ if ((await git.raw(['ls-files', '--unmerged', '-z'])).length)
135
+ throw new Error('Resolve conflicts before committing.');
136
+ if (!(await git.raw(['diff', '--cached', '--name-only', '-z'])).length)
137
+ throw new Error('Stage changes before committing.');
138
+ await git.commit([message.trim(), ...(description ? [description] : [])]);
139
+ }
140
+ return { snapshot, stage, unstage, commit };
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guito",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "Easily explore your git repositories.",
5
5
  "homepage": "https://github.com/danisss9/Guito#readme",
6
6
  "repository": {
@@ -50,7 +50,8 @@
50
50
  "test": "npm run build:server && node --test tests/*.test.mjs",
51
51
  "package:extension": "npm run build:ui && npm run package --workspace vscode-extension",
52
52
  "build:start": "npm run build && npm run start",
53
- "release": "npm run build && npm publish --access public"
53
+ "release": "npm run build && npm publish --access public",
54
+ "test:browser": "npm run build:ui && npm run build:server && playwright test"
54
55
  },
55
56
  "dependencies": {
56
57
  "@fastify/compress": "^9.2.0",
@@ -63,12 +64,14 @@
63
64
  },
64
65
  "devDependencies": {
65
66
  "@angular/build": "^20.0.0",
67
+ "@angular/cdk": "^20.2.14",
66
68
  "@angular/cli": "^20.0.0",
67
69
  "@angular/common": "^20.0.0",
68
70
  "@angular/compiler": "^20.0.0",
69
71
  "@angular/compiler-cli": "^20.0.0",
70
72
  "@angular/core": "^20.0.0",
71
73
  "@angular/platform-browser": "^20.0.0",
74
+ "@playwright/test": "^1.63.0",
72
75
  "@types/node": "^20.19.43",
73
76
  "rxjs": "~7.8.0",
74
77
  "tslib": "^2.6.0",
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from '@playwright/test';
2
+
3
+ export default defineConfig({
4
+ testDir: './tests/browser',
5
+ timeout: 30000,
6
+ workers: 2,
7
+ use: { baseURL: 'http://127.0.0.1:4173', viewport: { width: 1280, height: 800 }, trace: 'retain-on-failure' },
8
+ webServer: { command: 'node tests/browser/server.mjs', url: 'http://127.0.0.1:4173', reuseExistingServer: false },
9
+ });