Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a reference to how it works for simple PRs #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
# Reference Guide

- [Configuration](reference/configuration.md)
- [How it works - Simple PR](reference/how-it-works-simple.md)
118 changes: 118 additions & 0 deletions docs/reference/how-it-works-simple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# How it works - Simple PR

This section describes how `spr` works from a git perspective.
This is not required to use `spr`,
but more to understand how it works.

It follows the [simple PR](../user/simple.md) workflow.
Understanding that workflow will help understand the decisions made here.

## Creating the PR

Let's say you have a repo with a `main` branch:

```mermaid
gitGraph
commit id: "A"
commit id: "B"
```

Now you want to make a change.
You make a commit on the `main` branch with your change and the commit id is `C1`:

```mermaid
gitGraph
commit id: "A"
commit id: "B"
commit id: "C1"
```

When you are ready to submit a PR, you run `spr diff` from the head commit of the `main` branch (`C1`).
This will create a transient branch that is only used to create a PR on GitHub:

```mermaid
gitGraph
commit id: "A"
commit id: "B"
branch spr/username/commit-title-of-C1
checkout main
commit id: "C1"
checkout spr/username/commit-title-of-C1
commit id: "B->C1"
```

This `spr/username/commit-title-of-C1` branch is pushed to GitHub and used to open a PR against the `main` branch.
The transient branch is not something you really need to directly interact with;
`spr` takes care of keeping it up to date, creating the correct commits, etc.
All you need to do is continue working on the `main` branch.
Once the PR has been created for the `spr/username/commit-title-of-C1` branch,
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you forgot part of a sentence here?


The `C1` commit is updated with a few sections from the PR information.
A `Pull Request` section is added that links to the PR that was created.
This allows `spr` to know which branch/PR to update from only the commit.

## Amending the commit

Let's say your PR needed some changes.
What you'd do is make the changes to the commit that the PR was created from (in this case `C1`)
amending the changes to the commit.

```mermaid
gitGraph
commit id: "A"
commit id: "B"
branch spr/username/commit-title-of-C1
checkout main
commit id: "C2"
checkout spr/username/commit-title-of-C1
commit id: "B->C1"
```

The next time that you use `spr diff`,
it will compute the diff from `C1` to `C2`,
and push that to GitHub as an additional commit:

```mermaid
gitGraph
commit id: "A"
commit id: "B"
branch spr/username/commit-title-of-C1
checkout main
commit id: "C2"
checkout spr/username/commit-title-of-C1
commit id: "B->C1"
commit id: "C1->C2"
```

Pushing additional commits to the PR rather than rebasing the commits that are already on the PR works better with GitHub (discussions stay intact, commits aren't lost in the UI, changes between requests can be tracked, etc.).

If you make more changes,
it continues along this path:

```mermaid
gitGraph
commit id: "A"
commit id: "B"
branch spr/username/commit-title-of-C1
checkout main
commit id: "C3"
checkout spr/username/commit-title-of-C1
commit id: "B->C1"
commit id: "C1->C2"
commit id: "C2->C3"
```

## Landing the change

Once you're ready to merge the PR,
you would use `spr land` to merge the PR.
This will perform a squash merge on GitHub for the PR.
Once the branch has been merged on GitHub,
it will update the local `main` branch and delete the transient branch:

```mermaid
gitGraph
commit id: "A"
commit id: "B"
commit id: "C3"
```