Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ $ dev reset
$ dev mergeto <target-branch>
```

#### lock 命令:锁定/解锁代码提交

用于防止错误提交代码到远程仓库。当执行 `dev lock` 后,将无法使用 `dev ps` 或 `dev push` 命令提交代码,直到使用 `dev lock --unlock` 解锁。

包含如下功能:
+ 锁定提交:执行 `dev lock` 后,阻止 `dev ps` 和 `dev push` 命令的执行,避免错误提交代码。
+ 解锁提交:执行 `dev lock --unlock` 后,恢复正常的代码提交功能。

```shell
# 锁定,阻止代码提交
$ dev lock

# 解锁,允许代码提交
$ dev lock --unlock
```

### init 命令:初始化项目

通过 `dev init` 命令,可以快速初始化项目。当你在命令行中执行 `dev init` 时,系统会提示你输入项目目录名称。如果你输入 './',则项目会在当前目录下初始化。这使得在已有目录中快速开始一个新项目变得非常方便。
Expand Down
38 changes: 38 additions & 0 deletions packages/dev/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class GitPlugin extends BasePlugin {
usage: 'dev mergeto <target-branch>',
lifecycleEvents: [ 'do' ],
passingCommand: true,
},
lock: {
usage: 'dev lock',
lifecycleEvents: [ 'do' ],
passingCommand: true,
}
};

Expand All @@ -71,6 +76,7 @@ export class GitPlugin extends BasePlugin {
'release:do': this.handleReleaseDo.bind(this),
'info:do': this.handleInfoDo.bind(this),
'mergeto:do': this.handleMergetoDo.bind(this),
'lock:do': this.handleLockDo.bind(this),
};

gitInfo: any = {};
Expand Down Expand Up @@ -310,6 +316,17 @@ export class GitPlugin extends BasePlugin {
}

async handlePushDo() {
// Check if the repository is locked
const repoKey = this.core.cwd;
const isLocked = await getCache('lock', repoKey);
if (isLocked) {
console.error('');
console.error('>> Repository is locked! <<');
console.error('>> Cannot push changes when the repository is locked. <<');
console.error('>> Use "dev lock --unlock" to unlock the repository. <<');
console.error('');
process.exit(1);
}

await this.handleCommitDo();
const spin = new Spin({
Expand Down Expand Up @@ -651,4 +668,25 @@ export class GitPlugin extends BasePlugin {
console.error('Merge conflict detected. Please resolve the conflicts and commit the changes.');
}
}

async handleLockDo() {
const { options } = this.core.coreOptions;
const repoKey = this.core.cwd;

// Check if --unlock flag is provided
if (options.unlock) {
setCache('lock', repoKey, false);
console.log('');
console.log('>> Repository unlocked successfully! <<');
console.log('>> You can now push changes using "dev ps" or "dev push". <<');
console.log('');
} else {
setCache('lock', repoKey, true);
console.log('');
console.log('>> Repository locked successfully! <<');
console.log('>> "dev ps" and "dev push" commands are now blocked. <<');
console.log('>> Use "dev lock --unlock" to unlock the repository. <<');
console.log('');
}
}
}