git-tm 1.0.1 → 1.1.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/README.md +25 -37
- package/package.json +34 -4
- package/src/index.js +4 -0
- package/src/types/git.d.ts +214 -0
- package/src/types/graph.d.ts +33 -0
- package/src/types/index.d.ts +5 -0
- package/src/types/server.d.ts +15 -0
package/README.md
CHANGED
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
<h1>Git Time Machine</h1>
|
|
5
5
|
|
|
6
6
|
<p>Explore any Git repository's history in your browser.<br>
|
|
7
|
-
Commit graph, diffs, blame,
|
|
7
|
+
Commit graph, diffs, blame, insights and time travel between any two commits. One command, zero dependencies.</p>
|
|
8
8
|
|
|
9
9
|
<a href="https://www.npmjs.com/package/git-tm"><img src="https://img.shields.io/npm/v/git-tm?color=f05133" alt="npm version"></a>
|
|
10
10
|
<img src="https://img.shields.io/badge/dependencies-0-2ea44f" alt="zero dependencies">
|
|
11
11
|
<img src="https://img.shields.io/npm/l/git-tm" alt="license">
|
|
12
|
+
<a href="https://git-time-machine.js.org"><img src="https://img.shields.io/badge/docs-git--time--machine.js.org-0969da" alt="documentation"></a>
|
|
12
13
|
</div>
|
|
13
14
|
|
|
14
15
|
<br>
|
|
15
16
|
|
|
16
17
|

|
|
17
18
|
|
|
19
|
+
> **Full documentation:** [git-time-machine.js.org](https://git-time-machine.js.org) covers every feature, time travel, keyboard shortcuts, troubleshooting and the JavaScript API.
|
|
20
|
+
|
|
18
21
|
## Install
|
|
19
22
|
|
|
20
23
|
```bash
|
|
@@ -88,7 +91,7 @@ git tm
|
|
|
88
91
|
| --- | --- |
|
|
89
92
|
| `fix login` | Commit messages |
|
|
90
93
|
| `author:ada` | Commits by an author (name or email) |
|
|
91
|
-
| `path:src/app.js` | Commits that touched a path
|
|
94
|
+
| `path:src/app.js` | Commits that touched a path |
|
|
92
95
|
| `code:parseConfig` | Commits that added or removed a string (`git log -S`) |
|
|
93
96
|
| `a1b2c3d` | Jumps straight to a commit |
|
|
94
97
|
|
|
@@ -102,6 +105,21 @@ git tm
|
|
|
102
105
|
- Keyboard shortcuts: `j`/`k` to move, `Enter` to open, `t` for time travel mode, `←`/`→` to step through a journey, `/` to search, `Esc` to close, `g h`/`g c`/`g i` to switch views, `?` for help
|
|
103
106
|
- Works on phones and tablets
|
|
104
107
|
|
|
108
|
+
## Use it from code
|
|
109
|
+
|
|
110
|
+
git-tm is also a library, with TypeScript types included:
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
import { openRepo } from "git-tm";
|
|
114
|
+
|
|
115
|
+
const repo = await openRepo(".");
|
|
116
|
+
const { commits } = await repo.log({ ref: "main", limit: 20 });
|
|
117
|
+
const trip = await repo.range("v1.0.0", "main");
|
|
118
|
+
console.log(`${trip.addedCount} commits applied, ${trip.removedCount} undone`);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Entry points: `git-tm`, `git-tm/git`, `git-tm/server` and `git-tm/graph`. See the [API documentation](https://git-time-machine.js.org/guide.html#api) for every method.
|
|
122
|
+
|
|
105
123
|
## Privacy and safety
|
|
106
124
|
|
|
107
125
|
- Everything runs locally. The server binds to `127.0.0.1` and rejects requests for other host names, so other websites cannot read your repository.
|
|
@@ -115,17 +133,19 @@ git tm
|
|
|
115
133
|
```
|
|
116
134
|
src/
|
|
117
135
|
cli.js command-line entry point
|
|
136
|
+
index.js JavaScript API
|
|
118
137
|
server.js HTTP server and JSON API
|
|
119
138
|
git.js git commands and output parsing
|
|
120
139
|
public/ the web interface
|
|
121
140
|
js/graph.js commit graph layout
|
|
122
141
|
js/diff.js diff rendering
|
|
142
|
+
types/ TypeScript declarations
|
|
123
143
|
test/ node:test suites
|
|
124
144
|
```
|
|
125
145
|
|
|
126
|
-
##
|
|
146
|
+
## Contributing
|
|
127
147
|
|
|
128
|
-
There is nothing to install or build
|
|
148
|
+
Contributions are welcome! There is nothing to install or build:
|
|
129
149
|
|
|
130
150
|
```bash
|
|
131
151
|
git clone https://github.com/nandhu-44/Git-Time-Machine.git
|
|
@@ -133,39 +153,7 @@ cd Git-Time-Machine
|
|
|
133
153
|
node src/cli.js .
|
|
134
154
|
```
|
|
135
155
|
|
|
136
|
-
Run the tests
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
npm test
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Use your working copy as the global `git-tm` command (undo with `npm unlink -g git-tm`):
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
npm link
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Check exactly what would be published:
|
|
149
|
-
|
|
150
|
-
```bash
|
|
151
|
-
npm pack --dry-run
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Releasing
|
|
155
|
-
|
|
156
|
-
Pushing a version tag publishes to npm from GitHub Actions ([`publish.yml`](.github/workflows/publish.yml)), using npm trusted publishing, so no npm token is stored anywhere.
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
|
-
npm version patch
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
```bash
|
|
163
|
-
git push origin main --follow-tags
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
`npm version` bumps `package.json`, commits and creates the `vX.Y.Z` tag. Use `minor` or `major` as needed. The workflow checks that the tag matches `package.json`, runs the tests and publishes.
|
|
167
|
-
|
|
168
|
-
GitLab CI ([`.gitlab-ci.yml`](.gitlab-ci.yml)) runs the same tests. It publishes only if an `NPM_TOKEN` CI/CD variable is set, so a mirrored tag is not published twice.
|
|
156
|
+
Run the tests with `npm test`. See [CONTRIBUTING.md](CONTRIBUTING.md) for how the project is organised, its principles and how to send a pull request.
|
|
169
157
|
|
|
170
158
|
## Background
|
|
171
159
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-tm",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Explore any Git repository
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Explore any Git repository in your browser: commit graph, diffs, blame, insights and time travel between any two commits. Zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/types/index.d.ts",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./git": {
|
|
14
|
+
"types": "./src/types/git.d.ts",
|
|
15
|
+
"default": "./src/git.js"
|
|
16
|
+
},
|
|
17
|
+
"./server": {
|
|
18
|
+
"types": "./src/types/server.d.ts",
|
|
19
|
+
"default": "./src/server.js"
|
|
20
|
+
},
|
|
21
|
+
"./graph": {
|
|
22
|
+
"types": "./src/types/graph.d.ts",
|
|
23
|
+
"default": "./src/public/js/graph.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
6
27
|
"bin": {
|
|
7
28
|
"git-tm": "src/cli.js"
|
|
8
29
|
},
|
|
@@ -24,17 +45,26 @@
|
|
|
24
45
|
"git",
|
|
25
46
|
"git-tm",
|
|
26
47
|
"git-time-machine",
|
|
48
|
+
"time-travel",
|
|
27
49
|
"git-history",
|
|
50
|
+
"git-log",
|
|
51
|
+
"git-graph",
|
|
28
52
|
"commit-graph",
|
|
53
|
+
"git-gui",
|
|
54
|
+
"git-ui",
|
|
55
|
+
"history-viewer",
|
|
29
56
|
"diff",
|
|
30
57
|
"blame",
|
|
58
|
+
"compare",
|
|
31
59
|
"cli",
|
|
32
|
-
"
|
|
60
|
+
"developer-tools",
|
|
61
|
+
"visualization",
|
|
62
|
+
"api"
|
|
33
63
|
],
|
|
34
64
|
"author": "nandhu-44",
|
|
35
65
|
"license": "MIT",
|
|
36
66
|
"bugs": {
|
|
37
67
|
"url": "https://github.com/nandhu-44/Git-Time-Machine/issues"
|
|
38
68
|
},
|
|
39
|
-
"homepage": "https://
|
|
69
|
+
"homepage": "https://git-time-machine.js.org"
|
|
40
70
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/** Stands for the working tree (uncommitted changes) wherever a revision is accepted as a target. */
|
|
2
|
+
export const WORKTREE: "WORKTREE";
|
|
3
|
+
|
|
4
|
+
/** Error thrown for git failures and invalid input. `status` is an HTTP-style code (400, 404, 500, 504). */
|
|
5
|
+
export class GitError extends Error {
|
|
6
|
+
constructor(message: string, status?: number);
|
|
7
|
+
status: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface GitOptions {
|
|
11
|
+
/** Resolve with a Buffer instead of a string. */
|
|
12
|
+
raw?: boolean;
|
|
13
|
+
/** Written to git's stdin. */
|
|
14
|
+
input?: string | Buffer;
|
|
15
|
+
/** Stop reading after this many bytes of output; the result gets `truncated: true`. Default 64 MB. */
|
|
16
|
+
maxBytes?: number;
|
|
17
|
+
/** Kill git after this many milliseconds. Default 60 000. */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Run git in `cwd` with a clean, non-interactive environment and resolve with its stdout. */
|
|
22
|
+
export function git(cwd: string, args: string[], options: GitOptions & { raw: true }): Promise<Buffer & { truncated: boolean }>;
|
|
23
|
+
export function git(cwd: string, args: string[], options?: GitOptions): Promise<string>;
|
|
24
|
+
|
|
25
|
+
/** Open the repository containing `dir` (any folder inside it works). Throws GitError if there is none. */
|
|
26
|
+
export function openRepo(dir: string): Promise<Repo>;
|
|
27
|
+
|
|
28
|
+
/** Turn a remote URL (https or ssh) into a browsable https URL, or null. */
|
|
29
|
+
export function webUrl(url: string | null | undefined): string | null;
|
|
30
|
+
|
|
31
|
+
/** A branch, tag or HEAD decoration on a commit. */
|
|
32
|
+
export interface Ref {
|
|
33
|
+
type: "head" | "branch" | "remote" | "tag" | "detached";
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CommitSummary {
|
|
38
|
+
hash: string;
|
|
39
|
+
parents: string[];
|
|
40
|
+
author: string;
|
|
41
|
+
email: string;
|
|
42
|
+
/** Author date, Unix seconds. */
|
|
43
|
+
date: number;
|
|
44
|
+
committer: string;
|
|
45
|
+
committerEmail: string;
|
|
46
|
+
/** Commit date, Unix seconds. */
|
|
47
|
+
commitDate: number;
|
|
48
|
+
refs: Ref[];
|
|
49
|
+
subject: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Commit extends CommitSummary {
|
|
53
|
+
body: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface RepoInfo {
|
|
57
|
+
name: string;
|
|
58
|
+
root: string;
|
|
59
|
+
bare: boolean;
|
|
60
|
+
/** Current branch, or null when HEAD is detached. */
|
|
61
|
+
branch: string | null;
|
|
62
|
+
head: string | null;
|
|
63
|
+
branches: { name: string; target: string; upstream: string | null; ahead: number; behind: number; gone: boolean; date: number }[];
|
|
64
|
+
remotes: { name: string; remote: string; short: string; target: string; date: number }[];
|
|
65
|
+
tags: { name: string; target: string; annotated: boolean; message: string; date: number }[];
|
|
66
|
+
/** Number of changed or untracked paths in the working tree. */
|
|
67
|
+
changes: number;
|
|
68
|
+
emptyTree: string;
|
|
69
|
+
remoteUrl: string | null;
|
|
70
|
+
gitVersion: string | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface LogOptions {
|
|
74
|
+
/** Revision to start from. Default: HEAD plus every branch, remote and tag. */
|
|
75
|
+
ref?: string;
|
|
76
|
+
skip?: number;
|
|
77
|
+
/** Page size, 1 to 2000. Default 300. */
|
|
78
|
+
limit?: number;
|
|
79
|
+
/** Commit message contains this text (case-insensitive). */
|
|
80
|
+
message?: string;
|
|
81
|
+
/** Author name or email contains this text. */
|
|
82
|
+
author?: string;
|
|
83
|
+
/** Commits that add or remove this string (`git log -S`). */
|
|
84
|
+
code?: string;
|
|
85
|
+
/** Only commits touching this path. */
|
|
86
|
+
path?: string;
|
|
87
|
+
/** Follow renames of `path`. */
|
|
88
|
+
follow?: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface LogPage {
|
|
92
|
+
commits: CommitSummary[];
|
|
93
|
+
/** False when a filter makes the graph meaningless. */
|
|
94
|
+
graph: boolean;
|
|
95
|
+
/** True when there are no more pages. */
|
|
96
|
+
done: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface FileChange {
|
|
100
|
+
/** A, M, D, R (renamed), C (copied), T (type change) or ? (untracked). */
|
|
101
|
+
status: string;
|
|
102
|
+
path: string;
|
|
103
|
+
oldPath?: string;
|
|
104
|
+
similarity?: number;
|
|
105
|
+
oldMode?: string;
|
|
106
|
+
newMode?: string;
|
|
107
|
+
additions: number;
|
|
108
|
+
deletions: number;
|
|
109
|
+
binary: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface FileList {
|
|
113
|
+
from: string;
|
|
114
|
+
to: string;
|
|
115
|
+
files: FileChange[];
|
|
116
|
+
additions: number;
|
|
117
|
+
deletions: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface DiffOptions {
|
|
121
|
+
ignoreWhitespace?: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface Patch {
|
|
125
|
+
/** Unified diff text. */
|
|
126
|
+
patch: string;
|
|
127
|
+
truncated: boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface Range {
|
|
131
|
+
/** Commits only in `to`: applied by the move, newest first. */
|
|
132
|
+
added: CommitSummary[];
|
|
133
|
+
/** Commits only in `from`: undone by the move, newest first. */
|
|
134
|
+
removed: CommitSummary[];
|
|
135
|
+
/** Snapshots to step through, in order. The last entry is `to`. */
|
|
136
|
+
path: CommitSummary[];
|
|
137
|
+
addedCount: number;
|
|
138
|
+
removedCount: number;
|
|
139
|
+
mergeBase: string | null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface TreeEntry {
|
|
143
|
+
name: string;
|
|
144
|
+
path: string;
|
|
145
|
+
type: "tree" | "blob" | "commit";
|
|
146
|
+
mode: string;
|
|
147
|
+
oid: string;
|
|
148
|
+
size: number | null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface Blob {
|
|
152
|
+
path: string;
|
|
153
|
+
size: number;
|
|
154
|
+
binary: boolean;
|
|
155
|
+
truncated?: boolean;
|
|
156
|
+
content: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface Blame {
|
|
160
|
+
rev: string;
|
|
161
|
+
path: string;
|
|
162
|
+
/** Commit id for each line of the file. */
|
|
163
|
+
lines: string[];
|
|
164
|
+
commits: Record<string, { author?: string; email?: string; date?: number; subject?: string }>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface Insights {
|
|
168
|
+
total: number;
|
|
169
|
+
first: number | null;
|
|
170
|
+
last: number | null;
|
|
171
|
+
/** Commits per day, keyed YYYY-MM-DD (local time). */
|
|
172
|
+
days: Record<string, number>;
|
|
173
|
+
/** punch[day 0-6, Sunday first][hour 0-23] = commits. */
|
|
174
|
+
punch: number[][];
|
|
175
|
+
contributorCount: number;
|
|
176
|
+
/** Top 100 by commit count. */
|
|
177
|
+
contributors: { name: string; email: string; commits: number; first: number; last: number }[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A repository opened with openRepo(). Methods accept any revision git understands
|
|
182
|
+
* (branch, tag, commit id, HEAD~3, ...); results for immutable objects are cached.
|
|
183
|
+
*/
|
|
184
|
+
export interface Repo {
|
|
185
|
+
readonly root: string;
|
|
186
|
+
readonly gitDir: string;
|
|
187
|
+
readonly bare: boolean;
|
|
188
|
+
readonly name: string;
|
|
189
|
+
readonly emptyTree: string;
|
|
190
|
+
|
|
191
|
+
/** Run git in this repository. */
|
|
192
|
+
run(args: string[], options?: GitOptions): Promise<string>;
|
|
193
|
+
/** Full commit id for a revision, or WORKTREE. */
|
|
194
|
+
resolve(rev: string): Promise<string>;
|
|
195
|
+
info(): Promise<RepoInfo>;
|
|
196
|
+
/** Changes whenever refs, HEAD or the index change. */
|
|
197
|
+
fingerprint(): Promise<string>;
|
|
198
|
+
log(options?: LogOptions): Promise<LogPage>;
|
|
199
|
+
commit(rev: string): Promise<Commit>;
|
|
200
|
+
/** Branches, remote branches and tags whose history contains `rev`. */
|
|
201
|
+
containedIn(rev: string): Promise<{ branches: string[]; remotes: string[]; tags: string[] }>;
|
|
202
|
+
/** Changed files from `from` to `to`. `from` may be "" (empty tree); `to` may be WORKTREE. */
|
|
203
|
+
files(from: string, to: string, options?: DiffOptions): Promise<FileList>;
|
|
204
|
+
patch(from: string, to: string, file: string, oldFile?: string, options?: DiffOptions & { context?: number }): Promise<Patch>;
|
|
205
|
+
/** What moving from `from` to `to` applies and undoes, and the snapshots on the way. */
|
|
206
|
+
range(from: string, to: string): Promise<Range>;
|
|
207
|
+
tree(rev: string, dir?: string): Promise<{ rev: string; path: string; entries: TreeEntry[] }>;
|
|
208
|
+
blob(rev: string, file: string): Promise<Blob>;
|
|
209
|
+
blame(rev: string, file: string): Promise<Blame>;
|
|
210
|
+
/** Activity for one revision, or for all branches when omitted. */
|
|
211
|
+
insights(ref?: string): Promise<Insights>;
|
|
212
|
+
/** `git fetch --all --prune`. */
|
|
213
|
+
fetch(): Promise<string>;
|
|
214
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface GraphRow {
|
|
2
|
+
/** Column of this commit's node. */
|
|
3
|
+
col: number;
|
|
4
|
+
/** Columns whose line comes from the row above into the node. */
|
|
5
|
+
up: number[];
|
|
6
|
+
/** Columns the node's line continues into, one per parent. */
|
|
7
|
+
down: number[];
|
|
8
|
+
/** Columns that run straight through this row. */
|
|
9
|
+
pass: number[];
|
|
10
|
+
/** [from, to] lanes that move to another column in this row. */
|
|
11
|
+
shift: [number, number][];
|
|
12
|
+
/** Number of columns this row needs. */
|
|
13
|
+
width: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface LayoutState {
|
|
17
|
+
lanes: (string | null)[];
|
|
18
|
+
seen: Set<string>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Fresh layout state. */
|
|
22
|
+
export function createLayout(): LayoutState;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Lay out commits (newest first, children before parents), continuing from `state`
|
|
26
|
+
* so pages can be appended. Sets `commit.g` on each commit.
|
|
27
|
+
*/
|
|
28
|
+
export function layout<T extends { hash: string; parents: string[] }>(state: LayoutState, commits: T[]): LayoutState;
|
|
29
|
+
|
|
30
|
+
export const LANE_W: number;
|
|
31
|
+
|
|
32
|
+
/** SVG markup for one row of the graph. */
|
|
33
|
+
export function rowSvg(g: GraphRow, options: { height: number; maxLanes: number; merge?: boolean; head?: boolean }): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Server } from "node:http";
|
|
2
|
+
import type { Repo } from "./git.js";
|
|
3
|
+
|
|
4
|
+
export interface ServerOptions {
|
|
5
|
+
/** Load author avatars from GitHub and Gravatar. Default true. */
|
|
6
|
+
avatars?: boolean;
|
|
7
|
+
/** The host you will listen on. For loopback hosts, requests for other host names are rejected. Default "127.0.0.1". */
|
|
8
|
+
host?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** An HTTP server for the git-tm web interface and its JSON API. Call listen() to start it. */
|
|
12
|
+
export function createServer(repo: Repo, options?: ServerOptions): Server;
|
|
13
|
+
|
|
14
|
+
/** Listen on `port`, or the next free one (up to `attempts` tries). Resolves with the port used. */
|
|
15
|
+
export function listen(server: Server, port: number, host: string, attempts?: number): Promise<number>;
|