Skip to content

Improve commitFilesFromBase64 update handling#116

Merged
bluwy merged 1 commit into
mainfrom
refactor-core
Jun 19, 2026
Merged

Improve commitFilesFromBase64 update handling#116
bluwy merged 1 commit into
mainfrom
refactor-core

Conversation

@bluwy

@bluwy bluwy commented Jun 19, 2026

Copy link
Copy Markdown
Member

I found the code for handling create, update and force update a bit hard to follow, so I attempted to refactor it here. See the changesets for the full list of improvements as well.

Comment thread src/core.ts
throw new Error(`Could not determine sha for base ref "${baseRef}"`);
}
const targetSha = info.targetBranch?.target?.oid ?? null;
const sameBranchBase = "branch" in base && base.branch === branch;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the problem. It wasn't comparing the same branch base using shas.

Comment thread src/core.ts
Comment on lines -99 to -111
if (sameBranchBase) {
mode = force ? "force-update" : "update";
} else if (targetSha === null) {
// TODO: legit *creation* failure should be retried if `force === true`
mode = "create";
} else if (force) {
mode = "force-update";
} else if (targetSha === baseSha) {
mode = "update";
} else {
throw new Error(
`Branch ${branch} exists already and does not match base ${baseSha}, force is set to false`,
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a result, the conditions here are a bit weird. In the new code, I also flipped the force and targetSha === baseSha checks, because if targetSha === baseSha we can do updates just fine, we don't need to force update + temp branch stuff.

Comment thread src/core.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest of the code in this file are moving things around. I have the function order inverted compared to before, which fits my style of putting the main functions top, but happy to change this.

});
});

it("can commit to same branch as base", async () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The git diff is weird, but I basically only removed this test. We already tested this behaviour above so this test really wasn't testing anything new.

@bluwy bluwy added this pull request to the merge queue Jun 19, 2026
Merged via the queue into main with commit 67853bf Jun 19, 2026
11 checks passed
@bluwy bluwy deleted the refactor-core branch June 19, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants