Monorepo for Tangled forked from tangled.org/core
core blog posts pulls.md
7.3 kB · 195 lines
Markdown
at al10

--- atroot: true template: slug: pulls title: The lifecycle of a pull request subtitle: We shipped a bunch of PR features recently; here's how we built it date: 2025-04-16 image: https://assets.tangled.network/blog/hidden-ref.png authors: - name: Anirudh email: anirudh@tangled.sh handle: anirudh.fi - name: Akshay email: akshay@tangled.sh handle: oppi.li draft: false --- We've spent the last couple of weeks building out a pull request system for Tangled, and today we want to lift the hood and show you how it works. If you're new to Tangled, [read our intro](/intro) for the full story! You have three options to contribute to a repository: - Paste a patch on the web UI - Compare two local branches (you'll see this only if you're a collaborator on the repo) - Compare across forks Whatever you choose, at the core of every PR is the patch. First, you write some code. Then, you run `git diff` to produce a patch and make everyone's lives easier, or push to a branch, and we generate it ourselves by comparing against the target. ## patch generation When you create a PR from a branch, we create a "patch" by calculating the difference between your branch and the target branch. Consider this scenario: <figure class="max-w-[550px] m-auto flex flex-col items-center justify-center"> <img class="h-auto max-w-full" src="https://assets.tangled.network/blog/merge-base.png"> <figcaption class="text-center"><code>A</code> is the merge-base for <code>feature</code> and <code>main</code>.</figcaption> </figure> Your `feature` branch has advanced 2 commits since you first branched out, but in the meanwhile, `main` has also advanced 2 commits. Doing a trivial `git diff feature main` will produce a confusing patch: - the patch will apply the changes from `X` and `Y` - the patch will **revert** the changes from `B` and `C` We obviously do not want the second part! To only show the changes added by `feature`, we have to identify the "merge-base": the nearest common ancestor of `feature` and `main`. In thi…