Branches and GitHub
You don't need to know git to use Crank. This page is for when you want to know what Crank does to your repository, what it pushes to GitHub, and what it deletes.
The short version: Crank always starts from what's on GitHub, pushes finished work straight away so it can't be lost, never forces over anyone's work, deletes a job's branch only once it's certain nothing would be lost, and never deletes a topic or base branch.
The branches Crank uses
| Branch | Example | On GitHub as | Kept? |
|---|---|---|---|
| Base branch | main, version-2 | its own name | Never deleted by Crank |
| Topic branch | topic page | crank/page | Never deleted by Crank |
| Job branch | CB-123 | normally not pushed; crank/jobs/CB-123 only while the job is paused part way | Deleted once safely merged (see below) |
A job branch is named with the job's id at the time it was made. If the project's prefix changes later, the branch keeps its name until it's merged.
Source: CB-28, CB-78, CB-81.
Before every job
- Crank fetches from GitHub, including tags.
- If the topic's branch is on GitHub, Crank brings its copy up to date with it (only if that's a simple step forward).
- Then it makes the job's branch (for example
CB-123) from the topic branch. - Crank never merges
maininto a topic, or into a feature base likeversion-2. A topic only ever catches up with its own branch on GitHub and its own base. - Why: "the branch is always fetched from remote before starting anything", so a job never starts from stale code, and work pushed from elsewhere is picked up.
Source: CB-78.
After every job
- The job's branch is merged into the topic branch.
- The topic branch and tags are pushed to GitHub. After a topic merges into its base, the base and tags are pushed too.
- Why: "it's done all this work and could get lost". Finished work shouldn't exist only on one computer.
Source: CB-78.
Never force
- Crank never force-pushes a base branch or a topic branch, ever.
- The one exception is Crank's own
crank/jobs/CB-123branches, which it may update or delete only with a safety check (--force-with-lease) that fails if anyone else has pushed there since Crank last did. - If Crank can't move forward without forcing (both GitHub and your computer have new commits on a branch, or GitHub refuses a push), it stops work on that topic and makes it Needs operator, with a plain line such as "GitHub's crank/page has 2 commits that this computer doesn't have, and this computer has 3 that GitHub doesn't. Nothing was forced." Other topics carry on.
- Why: forcing could throw away someone's work. A person should decide.
Source: CB-78, CB-81.
Offline or no GitHub
If there's no GitHub remote, or GitHub can't be reached, Crank carries on locally, notes "not synced with GitHub: offline" on the topic, and pushes at the next chance.
Source: CB-78.
A paused job keeps its work
When a job stops part way (you pause or end its task, or a usage limit stops it):
- Any unsaved work is checked for secrets. If anything looks like a secret, nothing is saved, the job goes Needs operator, and Crank names the file.
- Otherwise it's saved as one commit marked "WIP CB-123 (paused by Crank)".
- The job's branch is pushed to GitHub as
crank/jobs/CB-123. - The topic's folder is put back clean, so the topic's next job can start.
- When the job resumes, on any computer, Crank fetches that branch, takes back only its own marked WIP commits (the work stays, ready for the next real commit), and carries on. It never rewrites a real commit.
- If someone else has pushed to
crank/jobs/CB-123, Crank keeps their commits, undoes nothing, and makes the job Needs operator. - If a
crank/jobs/CB-123branch already exists on GitHub and Crank didn't make it, Crank doesn't push to it; the job goes Needs operator. - Why: paused work used to sit unsaved in one folder, blocking that topic and lost if the computer died.
Source: CB-81.
When a job branch is deleted
A job's branch (for example CB-123) is deleted once its work is safely in its topic branch, and only when it's certain nothing would be lost. You never need CB-123 again after that: its work is in the topic, and the topic's history shows it.
Crank deletes a job branch only when all of these are true:
- Every commit on it is in the topic branch. With squash off, Crank checks the branch is fully contained in the topic. With squash on, it checks the topic has every change the job made.
- Crank made the branch.
- Nobody else has added to it: its tip is still the commit Crank last made or pushed.
- For the GitHub copy (
crank/jobs/CB-123), Crank fetches and checks again just before deleting, and the delete itself fails if anything changed.
It's deleted both on your computer and, if it was pushed, on GitHub. Otherwise the branch is kept, and the reason is written on the job and in the controller's log.
Why: old job branches pile up and say nothing the topic doesn't. But a branch someone else made, or added to, is theirs.
Source: CB-79, CB-81.
Topic and base branches are never deleted
Crank never deletes a topic branch or a base branch automatically, including when a topic is merged or removed.
Why: "unexpected for a project owner that doesn't understand git". Removing a topic in settings shouldn't silently delete code history.
Source: CB-79.
Squash
- Squash merges is a project setting, off by default, and each topic can override it ("Use the project setting", On or Off). The topic's choice wins.
- On: each job, and each topic when it merges, becomes one commit, titled with its id and title, for example "CB-123. Title".
- Off: every commit the builder made is kept.
- Why a choice: some people want a tidy history, others want every step.
Source: CB-79, CB-80.
Commit and branch names
Commits a job makes start with its id, for example "CB-12. Title". Tags are fetched before and pushed after every job, so release tags stay in step.
Source: CB-28, CB-78.