From 9c03b7e90729c8593a7a0f03c8d9630914ee9a1b Mon Sep 17 00:00:00 2001 From: Itay Maman <94941+imaman@users.noreply.github.com> Date: Sun, 29 Mar 2026 12:24:54 +0300 Subject: [PATCH 1/2] close --- src/dcc-cli.ts | 36 ++++++++++++++++++++++++++++++++++++ src/git-ops.ts | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/src/dcc-cli.ts b/src/dcc-cli.ts index e789604..8cde2c2 100644 --- a/src/dcc-cli.ts +++ b/src/dcc-cli.ts @@ -285,6 +285,36 @@ async function openPr() { await open(pr.openUrl) } +async function close() { + await gitOps.notOnMainBranch() + await gitOps.noUncommittedChanges() + + const pr = await graphqlOps.getCurrentPr() + if (pr) { + print(`Cannot close: there is an open PR (#${pr.number}: ${pr.title})`) + return + } + + const mainBranch = await gitOps.mainBranch() + const baselineCommit = await gitOps.findBaselineCommit(`origin/${mainBranch}`) + const changedFiles = await gitOps.getChangedFiles(baselineCommit) + if (changedFiles.length > 0) { + print(`Cannot close: there are ${changedFiles.length} changed file(s)`) + return + } + + const branch = await gitOps.getBranch() + const branchName = branch.name + + await gitOps.checkout(mainBranch) + await gitOps.deleteBranch(branchName) + print(`Deleted branch ${branchName}`) + + await gitOps.fetch('origin', mainBranch) + await gitOps.merge('origin', mainBranch) + print(`Synced ${mainBranch}`) +} + async function checkoutPr(a: { prNumber: number }) { await gitOps.noUncommittedChanges() @@ -413,6 +443,12 @@ yargs(hideBin(process.argv)) launch((a: { files: string[] }) => restore(a)), ) .command(['open', 'o'], 'Open the current PR files page in your browser', a => a, launch(openPr)) + .command( + ['close', 'cl'], + 'Delete the current branch and switch to main (only if no open PR and no diff)', + a => a, + launch(close), + ) .command( ['checkout ', 'co '], 'Checkout the branch of a PR by its number', diff --git a/src/git-ops.ts b/src/git-ops.ts index 29d9f39..4867e55 100644 --- a/src/git-ops.ts +++ b/src/git-ops.ts @@ -218,4 +218,12 @@ export class GitOps { async commitAll(message: string): Promise { await this.git.raw(['commit', '-m', message]) } + + async deleteBranch(branchName: string): Promise { + await this.git.branch(['-D', branchName]) + } + + async pull(): Promise { + await this.git.pull() + } } From ada7b86764cf797c722095f38c1b9108da25220d Mon Sep 17 00:00:00 2001 From: Itay Maman <94941+imaman@users.noreply.github.com> Date: Sun, 29 Mar 2026 12:28:39 +0300 Subject: [PATCH 2/2] unpull --- src/git-ops.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/git-ops.ts b/src/git-ops.ts index 4867e55..6ac5578 100644 --- a/src/git-ops.ts +++ b/src/git-ops.ts @@ -222,8 +222,4 @@ export class GitOps { async deleteBranch(branchName: string): Promise { await this.git.branch(['-D', branchName]) } - - async pull(): Promise { - await this.git.pull() - } }