xshell 1.3.24 → 1.3.25

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/git.d.ts CHANGED
@@ -37,6 +37,10 @@ export declare class Git {
37
37
  checkout(branch?: 'main'): Promise<void>;
38
38
  checkout(branch?: string): Promise<void>;
39
39
  _checkout(branch: string, create: boolean, remote_branch?: string): Promise<void>;
40
+ /** 基于远程分支创建相同且干净的本地分支 (reset),用于 ci
41
+ 会自动先通过 this.fetch 更新 remote_branch 对应的远程仓库
42
+ - branch: 远程分支名,必须类似 origin/main 这样的格式 */
43
+ checkout_remote(remote_branch: string): Promise<void>;
40
44
  get_version_info(version?: string): Promise<{
41
45
  version: string;
42
46
  branch: string;
@@ -45,6 +49,8 @@ export declare class Git {
45
49
  commiter: string;
46
50
  message: string;
47
51
  }>;
52
+ /** 重置分支到最后提交的状态 */
53
+ reset(remote_branch?: string): Promise<void>;
48
54
  }
49
55
  export interface GitVersionInfo {
50
56
  version: string;
package/git.js CHANGED
@@ -121,6 +121,23 @@ export class Git {
121
121
  ...remote_branch ? [remote_branch] : []
122
122
  ], print_no_command);
123
123
  }
124
+ /** 基于远程分支创建相同且干净的本地分支 (reset),用于 ci
125
+ 会自动先通过 this.fetch 更新 remote_branch 对应的远程仓库
126
+ - branch: 远程分支名,必须类似 origin/main 这样的格式 */
127
+ async checkout_remote(remote_branch) {
128
+ const [remote, name] = remote_branch.split2('/');
129
+ await this.fetch({ remote });
130
+ const branches = await this.get_branches(false);
131
+ if (!branches.includes(`remotes/${remote_branch}`))
132
+ throw new Error(`远程分支 ${remote_branch} 不存在`);
133
+ // 存在对应的本地分支
134
+ if (branches.includes(name)) {
135
+ await this._checkout(name, false);
136
+ await this.reset(remote_branch);
137
+ }
138
+ else
139
+ await this._checkout(name, true, remote_branch);
140
+ }
124
141
  async get_version_info(version) {
125
142
  const branch = await this.get_branch();
126
143
  const { hash, time, commiter, message } = (await this.get_last_commits(1))[0];
@@ -135,6 +152,15 @@ export class Git {
135
152
  message
136
153
  };
137
154
  }
155
+ /** 重置分支到最后提交的状态 */
156
+ async reset(remote_branch) {
157
+ console.log(`重置分支到${remote_branch ? ` ${remote_branch}` : '最后提交的状态'}`);
158
+ await this.call([
159
+ 'reset',
160
+ '--hard',
161
+ ...remote_branch ? [remote_branch] : []
162
+ ], print_no_command);
163
+ }
138
164
  }
139
165
  const print_stdout = { print: { code: false, command: false, stdout: true, stderr: true } };
140
166
  //# sourceMappingURL=git.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.3.24",
3
+ "version": "1.3.25",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/path.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare function extname(path: string): string;
54
54
  /** `/` */
55
55
  export declare const sep = "/";
56
56
  /** The platform-specific file delimiter. ';' or ':'. */
57
- export declare const delimiter: ";" | ":";
57
+ export declare const delimiter: ":" | ";";
58
58
  /** Returns an object from a path string - the opposite of format().
59
59
  @param path path to evaluate.
60
60
  @throws {TypeError} if `path` is not a string. */
@@ -81,7 +81,7 @@ export declare let path: {
81
81
  basename: typeof basename;
82
82
  extname: typeof extname;
83
83
  sep: string;
84
- delimiter: ";" | ":";
84
+ delimiter: ":" | ";";
85
85
  parse: typeof parse;
86
86
  format: typeof format;
87
87
  toNamespacedPath: typeof toNamespacedPath;
@@ -30733,6 +30733,12 @@ if (false) // removed by dead control flow
30733
30733
  /******/ if (cachedModule !== undefined) {
30734
30734
  /******/ return cachedModule.exports;
30735
30735
  /******/ }
30736
+ /******/ // Check if module exists (development only)
30737
+ /******/ if (__webpack_modules__[moduleId] === undefined) {
30738
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
30739
+ /******/ e.code = 'MODULE_NOT_FOUND';
30740
+ /******/ throw e;
30741
+ /******/ }
30736
30742
  /******/ // Create a new module (and put it into the cache)
30737
30743
  /******/ var module = __webpack_module_cache__[moduleId] = {
30738
30744
  /******/ id: moduleId,