xshell 1.0.68 → 1.0.69

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 (3) hide show
  1. package/git.d.ts +12 -0
  2. package/git.js +25 -0
  3. package/package.json +1 -1
package/git.d.ts CHANGED
@@ -13,6 +13,18 @@ export declare class Git {
13
13
  /** - print: `true` */
14
14
  get_branches(print?: boolean): Promise<string[]>;
15
15
  has_branch(branch: string): Promise<boolean>;
16
+ /** - last?: `4` */
17
+ log({ last, graph, format, }?: {
18
+ last?: number;
19
+ graph?: boolean;
20
+ format?: string;
21
+ }): Promise<import("./process.js").CallResult<string>>;
22
+ get_last_commits(last?: number): Promise<{
23
+ time: Date;
24
+ commiter: string;
25
+ hash: string;
26
+ message: string;
27
+ }[]>;
16
28
  fetch(print?: boolean): Promise<void>;
17
29
  /** - branch?: `'main'` */
18
30
  checkout(branch?: 'main'): Promise<void>;
package/git.js CHANGED
@@ -51,6 +51,31 @@ export class Git {
51
51
  return (await this.get_branches(false))
52
52
  .includes(branch);
53
53
  }
54
+ /** - last?: `4` */
55
+ async log({ last = 4, graph = false, format, } = {}) {
56
+ if (!graph && !format)
57
+ // 多行 commit message 会被 join 在一起,用空格隔开
58
+ format = ['ct', 'cn', 'H', 's'].map(x => `%${x}`).join('%x00');
59
+ return this.call([
60
+ 'log',
61
+ ...graph ? ['--graph'] : [],
62
+ `-${last}`,
63
+ ...format ? [`--pretty=format:${format}`] : [],
64
+ ], { color: !format, print: !format });
65
+ }
66
+ async get_last_commits(last = 100) {
67
+ const { stdout } = await this.log({ last });
68
+ return stdout.split_lines()
69
+ .map(line => {
70
+ const [unixtime, commiter, hash, message] = line.split('\x00');
71
+ return {
72
+ time: new Date(Number(unixtime) * 1000),
73
+ commiter,
74
+ hash,
75
+ message
76
+ };
77
+ });
78
+ }
54
79
  async fetch(print = true) {
55
80
  await this.call(['fetch', '--all', '--prune'], { print: { code: false, command: false, stdout: true, stderr: true } });
56
81
  if (print)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {