From f241453dcf067b6fb73cc566bd09801646c42dc1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 05:56:29 +0000 Subject: [PATCH 1/4] Initial plan From c2d24fb0ae54956570447000d8e5a3076d150749 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 06:00:37 +0000 Subject: [PATCH 2/4] feat: add dev lock command to prevent accidental pushes Co-authored-by: echosoar <14832743+echosoar@users.noreply.github.com> --- packages/dev/src/git.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/dev/src/git.ts b/packages/dev/src/git.ts index c01cde9..34964a7 100644 --- a/packages/dev/src/git.ts +++ b/packages/dev/src/git.ts @@ -58,6 +58,11 @@ export class GitPlugin extends BasePlugin { usage: 'dev mergeto ', lifecycleEvents: [ 'do' ], passingCommand: true, + }, + lock: { + usage: 'dev lock', + lifecycleEvents: [ 'do' ], + passingCommand: true, } }; @@ -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 = {}; @@ -310,6 +316,16 @@ export class GitPlugin extends BasePlugin { } async handlePushDo() { + // Check if the repository is locked + const isLocked = await getCache('lock', 'status'); + 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({ @@ -651,4 +667,24 @@ 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; + + // Check if --unlock flag is provided + if (options.unlock) { + setCache('lock', 'status', 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', 'status', 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(''); + } + } } From fbd5fcc3453151668c4353367be22cee57d55b60 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 06:02:02 +0000 Subject: [PATCH 3/4] docs: add documentation for dev lock command Co-authored-by: echosoar <14832743+echosoar@users.noreply.github.com> --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 56e3c27..ca05067 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,22 @@ $ dev reset $ dev mergeto ``` +#### 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` 时,系统会提示你输入项目目录名称。如果你输入 './',则项目会在当前目录下初始化。这使得在已有目录中快速开始一个新项目变得非常方便。 From 7d228c6fc8e24c09cae1c3608e51f0871629a61c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 07:13:25 +0000 Subject: [PATCH 4/4] fix: make lock per-repository instead of global Co-authored-by: echosoar <14832743+echosoar@users.noreply.github.com> --- packages/dev/src/git.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/dev/src/git.ts b/packages/dev/src/git.ts index 34964a7..b4741fe 100644 --- a/packages/dev/src/git.ts +++ b/packages/dev/src/git.ts @@ -317,7 +317,8 @@ export class GitPlugin extends BasePlugin { async handlePushDo() { // Check if the repository is locked - const isLocked = await getCache('lock', 'status'); + const repoKey = this.core.cwd; + const isLocked = await getCache('lock', repoKey); if (isLocked) { console.error(''); console.error('>> Repository is locked! <<'); @@ -670,16 +671,17 @@ export class GitPlugin extends BasePlugin { async handleLockDo() { const { options } = this.core.coreOptions; + const repoKey = this.core.cwd; // Check if --unlock flag is provided if (options.unlock) { - setCache('lock', 'status', false); + 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', 'status', true); + setCache('lock', repoKey, true); console.log(''); console.log('>> Repository locked successfully! <<'); console.log('>> "dev ps" and "dev push" commands are now blocked. <<');