2017-11-23 20:21:57 +01:00
|
|
|
# Zulip-specific tools
|
|
|
|
|
2017-11-26 18:14:28 +01:00
|
|
|
This article documents several useful tools that can save you a lot of
|
|
|
|
time when working with Git on the Zulip project.
|
2017-11-23 20:21:57 +01:00
|
|
|
|
2020-08-11 01:47:54 +02:00
|
|
|
## Set up Git repo script
|
2017-11-23 20:21:57 +01:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
**Extremely useful**. In the `tools` directory of
|
2018-11-29 23:09:03 +01:00
|
|
|
[zulip/zulip][github-zulip-zulip] you'll find a bash script
|
|
|
|
`setup-git-repo`. This script installs a pre-commit hook, which will
|
|
|
|
run each time you `git commit` to automatically run
|
2019-09-30 19:37:56 +02:00
|
|
|
[Zulip's linter suite](../testing/linters.md) on just the files that
|
2018-11-29 23:09:03 +01:00
|
|
|
the commit modifies (which is really fast!). The hook passes no matter
|
|
|
|
the result of the linter, but you should still pay attention to any
|
|
|
|
notices or warnings it displays.
|
2017-11-23 20:21:57 +01:00
|
|
|
|
|
|
|
It's simple to use. Make sure you're in the clone of zulip and run the following:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2017-11-23 20:21:57 +01:00
|
|
|
$ ./tools/setup-git-repo
|
|
|
|
```
|
|
|
|
|
|
|
|
The script doesn't produce any output if successful. To check that the hook has
|
|
|
|
been installed, print a directory listing for `.git/hooks` and you should see
|
|
|
|
something similar to:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2017-11-23 20:21:57 +01:00
|
|
|
$ ls -l .git/hooks
|
|
|
|
pre-commit -> ../../tools/pre-commit
|
|
|
|
```
|
|
|
|
|
2018-12-10 17:12:58 +01:00
|
|
|
## Configure continuous integration for your Zulip fork
|
2017-11-23 20:21:57 +01:00
|
|
|
|
2018-12-10 17:12:58 +01:00
|
|
|
You might also wish to [configure continuous integration for your fork][zulip-git-guide-ci].
|
2017-11-23 20:21:57 +01:00
|
|
|
|
|
|
|
## Reset to pull request
|
|
|
|
|
|
|
|
`tools/reset-to-pull-request` is a short-cut for [checking out a pull request
|
|
|
|
locally][zulip-git-guide-fetch-pr]. It works slightly differently from the method
|
|
|
|
described above in that it does not create a branch for the pull request
|
|
|
|
checkout.
|
|
|
|
|
|
|
|
**This tool checks for uncommitted changes, but it will move the
|
2021-08-20 22:54:08 +02:00
|
|
|
current branch using `git reset --hard`. Use with caution.**
|
2017-11-23 20:21:57 +01:00
|
|
|
|
|
|
|
First, make sure you are working in a branch you want to move (in this
|
2021-09-01 00:15:31 +02:00
|
|
|
example, we'll use the local `main` branch). Then run the script
|
2017-11-23 20:21:57 +01:00
|
|
|
with the ID number of the pull request as the first argument.
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2021-09-01 00:15:31 +02:00
|
|
|
$ git checkout main
|
|
|
|
Switched to branch 'main'
|
|
|
|
Your branch is up-to-date with 'origin/main'.
|
2017-11-23 20:21:57 +01:00
|
|
|
|
|
|
|
$ ./tools/reset-to-pull-request 1900
|
|
|
|
+ request_id=1900
|
|
|
|
+ git fetch upstream pull/1900/head
|
|
|
|
remote: Counting objects: 159, done.
|
|
|
|
remote: Compressing objects: 100% (17/17), done.
|
|
|
|
remote: Total 159 (delta 94), reused 91 (delta 91), pack-reused 51
|
|
|
|
Receiving objects: 100% (159/159), 55.57 KiB | 0 bytes/s, done.
|
|
|
|
Resolving deltas: 100% (113/113), completed with 54 local objects.
|
|
|
|
From https://github.com/zulip/zulip
|
|
|
|
* branch refs/pull/1900/head -> FETCH_HEAD
|
|
|
|
+ git reset --hard FETCH_HEAD
|
|
|
|
HEAD is now at 2bcd1d8 troubleshooting tip about provisioning
|
|
|
|
```
|
|
|
|
|
|
|
|
## Fetch a pull request and rebase
|
|
|
|
|
|
|
|
`tools/fetch-rebase-pull-request` is a short-cut for [checking out a pull
|
|
|
|
request locally][zulip-git-guide-fetch-pr] in its own branch and then updating it with any
|
2021-09-01 03:13:20 +02:00
|
|
|
changes from `upstream/main` with `git rebase`.
|
2017-11-23 20:21:57 +01:00
|
|
|
|
|
|
|
Run the script with the ID number of the pull request as the first argument.
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2017-11-23 20:21:57 +01:00
|
|
|
$ tools/fetch-rebase-pull-request 1913
|
|
|
|
+ request_id=1913
|
|
|
|
+ git fetch upstream pull/1913/head
|
|
|
|
remote: Counting objects: 4, done.
|
|
|
|
remote: Compressing objects: 100% (4/4), done.
|
|
|
|
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
|
|
|
|
Unpacking objects: 100% (4/4), done.
|
|
|
|
From https://github.com/zulip/zulip
|
|
|
|
* branch refs/pull/1913/head -> FETCH_HEAD
|
2021-09-01 00:15:31 +02:00
|
|
|
+ git checkout upstream/main -b review-1913
|
|
|
|
Branch review-1913 set up to track remote branch main from upstream.
|
2017-11-23 20:21:57 +01:00
|
|
|
Switched to a new branch 'review-1913'
|
|
|
|
+ git reset --hard FETCH_HEAD
|
2020-03-17 13:57:10 +01:00
|
|
|
HEAD is now at 99aa2bf Add provision.py fails issue in common errors
|
2017-11-23 20:21:57 +01:00
|
|
|
+ git pull --rebase
|
|
|
|
Current branch review-1913 is up to date.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Fetch a pull request without rebasing
|
|
|
|
|
|
|
|
`tools/fetch-pull-request` is a similar to `tools/fetch-rebase-pull-request`, but
|
2021-09-01 03:13:20 +02:00
|
|
|
it does not rebase the pull request against `upstream/main`, thereby getting
|
2017-11-23 20:21:57 +01:00
|
|
|
exactly the same repository state as the commit author had.
|
|
|
|
|
|
|
|
Run the script with the ID number of the pull request as the first argument.
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2017-11-23 20:21:57 +01:00
|
|
|
$ tools/fetch-pull-request 5156
|
|
|
|
+ git diff-index --quiet HEAD
|
|
|
|
+ request_id=5156
|
|
|
|
+ remote=upstream
|
|
|
|
+ git fetch upstream pull/5156/head
|
|
|
|
From https://github.com/zulip/zulip
|
|
|
|
* branch refs/pull/5156/head -> FETCH_HEAD
|
|
|
|
+ git checkout -B review-original-5156
|
|
|
|
Switched to a new branch 'review-original-5156'
|
|
|
|
+ git reset --hard FETCH_HEAD
|
|
|
|
HEAD is now at 5a1e982 tools: Update clean-branches to clean review branches.
|
|
|
|
```
|
|
|
|
|
2019-02-18 19:39:46 +01:00
|
|
|
## Push to a pull request
|
|
|
|
|
|
|
|
`tools/push-to-pull-request` is primarily useful for maintainers who
|
2021-08-20 21:53:28 +02:00
|
|
|
are merging other users' commits into a Zulip repository. After doing
|
2019-02-18 19:39:46 +01:00
|
|
|
`reset-to-pull-request` or `fetch-pull-request` and making some
|
|
|
|
changes, you can push a branch back to a pull request with e.g.
|
2021-08-20 21:53:28 +02:00
|
|
|
`tools/push-to-pull-request 1234`. This is useful for a few things:
|
2019-02-18 19:39:46 +01:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Getting CI to run and enabling you to use the GitHub "Merge" buttons
|
2019-02-18 19:39:46 +01:00
|
|
|
to merge a PR after you make some corrections to a PR, without
|
|
|
|
waiting for an extra round trip with the PR author.
|
2021-08-20 21:45:39 +02:00
|
|
|
- For commits that aren't ready to merge yet, communicating clearly
|
2019-02-18 19:39:46 +01:00
|
|
|
any changes you'd like to see happen that are easier for you to
|
|
|
|
explain by just editing the code than in words.
|
2021-08-20 21:45:39 +02:00
|
|
|
- Saving a contributor from needing to duplicate any rebase work that
|
2019-02-18 19:39:46 +01:00
|
|
|
you did as part of integrating parts of the PR.
|
|
|
|
|
|
|
|
You'll likely want to comment on the PR after doing so, to ensure that
|
|
|
|
the original contributor knows to pull your changes rather than
|
|
|
|
accidentally overwriting them with a force push when they make their
|
|
|
|
next batch of changes.
|
|
|
|
|
|
|
|
Note that in order to do this you need permission to do such a push,
|
|
|
|
which GitHub offers by default to users with write access to the
|
2021-08-20 21:53:28 +02:00
|
|
|
repository. For multiple developers collaborating on a PR, you can
|
2019-02-18 19:39:46 +01:00
|
|
|
achieve this by granting other users permission to write to your fork.
|
|
|
|
|
2017-11-23 20:21:57 +01:00
|
|
|
## Delete unimportant branches
|
|
|
|
|
|
|
|
`tools/clean-branches` is a shell script that removes branches that are either:
|
|
|
|
|
2021-09-01 03:13:20 +02:00
|
|
|
1. Local branches that are ancestors of `origin/main`.
|
|
|
|
2. Branches in origin that are ancestors of `origin/main` and named like `$USER-*`.
|
2017-11-23 20:21:57 +01:00
|
|
|
3. Review branches created by `tools/fetch-rebase-pull-request` and `tools/fetch-pull-request`.
|
|
|
|
|
2021-09-01 00:15:31 +02:00
|
|
|
First, make sure you are working in branch `main`. Then run the script without any
|
2017-11-23 20:21:57 +01:00
|
|
|
arguments for default behavior. Since removing review branches can inadvertently remove any
|
|
|
|
feature branches whose names are like `review-*`, it is not done by default. To
|
|
|
|
use it, run `tools/clean-branches --reviews`.
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2017-11-23 20:21:57 +01:00
|
|
|
$ tools/clean-branches --reviews
|
|
|
|
Deleting local branch review-original-5156 (was 5a1e982)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Merge conflict on yarn.lock file
|
|
|
|
|
|
|
|
If there is a merge conflict on yarn.lock, yarn should be run to
|
2021-08-20 22:54:08 +02:00
|
|
|
regenerate the file. _Important_ don't delete the yarn.lock file. Check out the
|
2021-09-01 03:13:20 +02:00
|
|
|
latest one from `origin/main` so that yarn knows the previous asset versions.
|
2017-11-23 20:21:57 +01:00
|
|
|
|
|
|
|
Run the following commands
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```bash
|
2021-09-01 00:15:31 +02:00
|
|
|
git checkout origin/main -- yarn.lock
|
2017-11-23 20:21:57 +01:00
|
|
|
yarn install
|
|
|
|
git add yarn.lock
|
|
|
|
git rebase --continue
|
|
|
|
```
|
|
|
|
|
|
|
|
[github-zulip-zulip]: https://github.com/zulip/zulip/
|
2020-10-13 23:50:18 +02:00
|
|
|
[zulip-git-guide-fetch-pr]: ../git/collaborate.html#check-out-a-pull-request-locally
|
2019-04-06 02:58:44 +02:00
|
|
|
[zulip-git-guide-ci]: ../git/cloning.html#step-3-configure-continuous-integration-for-your-fork
|