Improve commitFilesFromBase64 update handling#116
Conversation
| 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; |
There was a problem hiding this comment.
This was one of the problem. It wasn't comparing the same branch base using shas.
| 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`, | ||
| ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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.
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.