Skip to content

Commit 0bc16a8

Browse files
committed
Don't try to open a PR if there are no changed files
1 parent fb39c6f commit 0bc16a8

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/commands/fix/git.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ export async function gitCreateAndPushBranchIfNeeded(
120120
cwd = process.cwd()
121121
): Promise<boolean> {
122122
if (await gitBranchExists(branch, cwd)) {
123-
logger.warn(`Branch "${branch}" already exists. Skipping creation.`)
124-
return false
123+
logger.warn(`Branch "${branch}" already exists, skipping creation.`)
124+
return true
125125
}
126-
await spawn('git', ['checkout', '-b', branch], { cwd })
127126
const moddedFilepaths = (await gitUnstagedModifiedFiles(cwd)).filter(p => {
128127
const basename = path.basename(p)
129128
return (
@@ -132,9 +131,12 @@ export async function gitCreateAndPushBranchIfNeeded(
132131
basename === 'pnpm-lock.yaml'
133132
)
134133
})
135-
if (moddedFilepaths.length) {
136-
await spawn('git', ['add', ...moddedFilepaths], { cwd })
134+
if (!moddedFilepaths.length) {
135+
logger.warn('Nothing to commit, skipping push.')
136+
return false
137137
}
138+
await spawn('git', ['checkout', '-b', branch], { cwd })
139+
await spawn('git', ['add', ...moddedFilepaths], { cwd })
138140
await spawn('git', ['commit', '-m', commitMsg], { cwd })
139141
await spawn('git', ['push', '--set-upstream', 'origin', branch], { cwd })
140142
return true

src/commands/fix/npm-fix.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,16 @@ export async function npmFix(
279279
errored = true
280280
}
281281

282-
if (!errored && shouldOpenPr) {
282+
if (
283+
!errored &&
284+
shouldOpenPr &&
283285
// eslint-disable-next-line no-await-in-loop
284-
await gitCreateAndPushBranchIfNeeded(
286+
(await gitCreateAndPushBranchIfNeeded(
285287
branch,
286288
getSocketCommitMessage(oldPurl, newVersion, workspaceName),
287289
cwd
288-
)
290+
))
291+
) {
289292
// eslint-disable-next-line no-await-in-loop
290293
const prResponse = await openGitHubPullRequest(
291294
owner,

src/commands/fix/pnpm-fix.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,16 @@ export async function pnpmFix(
340340
errored = true
341341
}
342342

343-
if (!errored && shouldOpenPr) {
343+
if (
344+
!errored &&
345+
shouldOpenPr &&
344346
// eslint-disable-next-line no-await-in-loop
345-
await gitCreateAndPushBranchIfNeeded(
347+
(await gitCreateAndPushBranchIfNeeded(
346348
branch,
347349
getSocketCommitMessage(oldPurl, newVersion, workspaceName),
348350
cwd
349-
)
351+
))
352+
) {
350353
// eslint-disable-next-line no-await-in-loop
351354
const prResponse = await openGitHubPullRequest(
352355
owner,

0 commit comments

Comments
 (0)