EXTRACTION.md

 1# Extracting an extension to dedicated repo
 2
 3These are some notes of how to extract an extension from the main zed repository and generate a new repository which preserves the history as best as possible.  In the this example we will be extracting the `ruby` extension, substitute as appropriate.
 4
 5## Pre-requisites
 6
 7Install [git-filter-repo](https://github.com/newren/git-filter-repo/blob/main/INSTALL.md):
 8
 9```
10brew install git-filter-repo
11```
12
13## Process
14
151. Create an expressions.txt file somewhere (e.g. `~/projects/expressions.txt`)
16
17```
18ruby: ==>
19extension: ==>
20chore: ==>
21zed_extension_api: ==>
22regex:(?<![\[a-zA-Z0-9])(#[0-9]{3,5})==>zed-industries/zed\1
23```
24
25This file takes the form of `patern==>replacement`, where the replacement is optional.
26Note whitespace matters so `ruby: ==>` is removing the `ruby:` prefix from a commit messages and adding a space after `==> ` means the replacement begins with a space.  Regex capture groups are numbered `\1`, `\2`, etc.
27
28See: [Git Filter Repo Docs](https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html) for more.
29
302. Create a clean clone the zed repository, delete tags, delete branches and do the work.
31
32> **Note**
33> If you get `zsh: command not found: #` errors, run:
34> `setopt interactive_comments && echo "setopt interactive_comments" >> ~/.zshrc`
35
36```sh
37rm -rf zed3
38git clone --single-branch --no-tags git@github.com:zed-industries/zed.git zed3
39cd zed3
40
41# This removes the LICENSE symlink
42git filter-repo --invert-paths --path extensions/ruby/LICENSE-APACHE
43
44git filter-repo \
45    --use-mailmap \
46    --subdirectory-filter extensions/ruby/ \
47    --path LICENSE-APACHE \
48    --replace-message ~/projects/expressions.txt
49```
50
513. Review the commits.
52
53This is your last chance to make any modifications.
54If you don't fix it now, it'll be wrong forever.
55
56For example, a previous commit message was `php/ruby: bump version to 0.0.5`
57which was replaced with `php/bump version to 0.0.5`
58so I added a new line to expressions.txt with `php/==>`
59and next run it became `bump version to 0.0.5`.
60
614. [Optional] Generate tags
62
63You can always add tags later, but it's a nice touch.
64
65Show you all commits that mention a version number:
66
67```sh
68git log --grep="(\d+\.\d+\.\d+\.)" --perl-regexp --oneline --reverse
69```
70
71Then just:
72```
73git tag v0.0.2 abcd1234
74git tag v0.0.3 deadbeef
75```
76
77Usually the initial extraction didn't mention a version number so you can just do that one manually.
78
794. Push to the new repo
80
81Create a new empty repo on github under the [zed-extensions](https://github.com/zed-extensions) organization.
82
83```
84git remote add origin git@github.com:zed-extensions/ruby
85git push origin main --tags
86```
87
885. [Optional]