Skip to content

Commit 9f8c3ea

Browse files
committed
fix: use checkout -B to preserve uncommitted changes
- Use checkout -B instead of reset + checkout - Preserves version bump changes made before PR creation - Merge remote changes instead of rebase to handle conflicts
1 parent 0cb544a commit 9f8c3ea

3 files changed

Lines changed: 11 additions & 21 deletions

File tree

dist/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130428,16 +130428,11 @@ async function createOrUpdateVersionPR(octokit, context3, options) {
130428130428
core3.debug(`Base branch: ${baseBranch}, Version branch: ${options.branch}`);
130429130429
await ensureBranchExists(octokit, owner, repo, options.branch, baseBranch);
130430130430
git2(`fetch origin ${options.branch}`);
130431+
git2(`checkout -B ${options.branch}`);
130431130432
try {
130432-
git2("reset --hard HEAD");
130433+
git2(`merge origin/${options.branch} --no-edit`);
130433130434
} catch {
130434-
core3.debug("No changes to reset");
130435-
}
130436-
git2(`checkout ${options.branch}`);
130437-
try {
130438-
git2(`pull origin ${options.branch} --rebase`);
130439-
} catch {
130440-
core3.debug("No remote changes to pull");
130435+
core3.debug("No remote changes to merge or merge conflict (will be resolved by push)");
130441130436
}
130442130437
git2('config user.name "contractual[bot]"');
130443130438
git2('config user.email "contractual[bot]@users.noreply.github.com"');

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github/pull-requests.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,18 @@ export async function createOrUpdateVersionPR(
5353
// Ensure branch exists
5454
await ensureBranchExists(octokit, owner, repo, options.branch, baseBranch);
5555

56-
// Checkout the version branch (force to handle any uncommitted changes)
56+
// Fetch the version branch
5757
git(`fetch origin ${options.branch}`);
5858

59-
try {
60-
// Try to reset any uncommitted changes before checkout
61-
git('reset --hard HEAD');
62-
} catch {
63-
core.debug('No changes to reset');
64-
}
65-
66-
git(`checkout ${options.branch}`);
59+
// Use checkout -B to create or reset the branch, keeping uncommitted changes
60+
// This handles the case where the branch exists with stale state
61+
git(`checkout -B ${options.branch}`);
6762

68-
// Pull latest changes to avoid conflicts
63+
// Merge any remote changes to stay in sync
6964
try {
70-
git(`pull origin ${options.branch} --rebase`);
65+
git(`merge origin/${options.branch} --no-edit`);
7166
} catch {
72-
core.debug('No remote changes to pull');
67+
core.debug('No remote changes to merge or merge conflict (will be resolved by push)');
7368
}
7469

7570
// Configure git identity

0 commit comments

Comments
 (0)