|
| 1 | +# Working with workspaces |
| 2 | + |
| 3 | +--- |
| 4 | +***NOTE*** |
| 5 | + |
| 6 | +All the commands are included from the file `workspaces.t` |
| 7 | +which can be run with [cram](https://bitheap.org/cram/). |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +Josh really starts to shine when using workspaces. |
| 12 | + |
| 13 | +Simply put, they are a list of files and folders, remapped from the central repository |
| 14 | +to a new repository. |
| 15 | +For example, a shared library could be used by various workspaces, each mapping it to |
| 16 | +their appropriate subdirectory. |
| 17 | + |
| 18 | +In this chapter, we're going to set up a new git repository with a couple of libraries, |
| 19 | +and then use it to demonstrate the use of workspaces. |
| 20 | + |
| 21 | +## Test set-up |
| 22 | +--- |
| 23 | +***NOTE*** |
| 24 | + |
| 25 | +The following section describes how to set-up a local git server with made-up content |
| 26 | +for the sake of this tutorial. |
| 27 | +You're free to follow it, or to use your own existing repository, in which case you |
| 28 | +can skip to the next section |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +To host the repository for this test, we need a git server. |
| 33 | +We're going to run git as a [cgi](https://en.wikipedia.org/wiki/Common_Gateway_Interface) |
| 34 | +program using its provided http backend, served with the test server included in |
| 35 | +the [hyper\_cgi](https://crates.io/crates/hyper_cgi) crate. |
| 36 | + |
| 37 | +### Serving the git repo |
| 38 | +First, we create a *bare* repository, which will be served by hyper\_cgi. We enable |
| 39 | +the option `http.receivepack` to allow the use of `git push` from the clients. |
| 40 | + |
| 41 | +```shell |
| 42 | +{{#include workspaces.t:git_setup}} |
| 43 | +``` |
| 44 | + |
| 45 | +Then we start the server which will allow clients to access the repository through |
| 46 | +http. |
| 47 | + |
| 48 | +```shell |
| 49 | +{{#include workspaces.t:git_server}} |
| 50 | +``` |
| 51 | + |
| 52 | +Our server is ready, serving all the repos in the `remote` folder on port `8001`. |
| 53 | + |
| 54 | +```shell |
| 55 | +{{#include workspaces.t:clone}} |
| 56 | +``` |
| 57 | + |
| 58 | +### Adding some content |
| 59 | +Of course, the repository is for now empty, and we need to populate it. |
| 60 | +The following script creates a couple of libraries, as well as two applications that use |
| 61 | +them. |
| 62 | + |
| 63 | +```shell |
| 64 | +{{#include workspaces.t:populate}} |
| 65 | +``` |
| 66 | + |
| 67 | +## Creating our first workspace |
| 68 | +Now that we have a git repo populated with content, let's serve it through josh: |
| 69 | + |
| 70 | +```shell |
| 71 | +{{#include workspaces.t:docker_josh}} |
| 72 | +``` |
| 73 | + |
| 74 | +--- |
| 75 | +**NOTE** |
| 76 | + |
| 77 | +For the sake of this example, we run docker with --network="host" instead of publishing the port. |
| 78 | +This is so that docker can access localhost, where our ad-hoc git repository is served. |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +To facilitate developement on applications 1 and 2, we want to create workspaces for them. |
| 83 | +Creating a new workspace looks very similar to checking out a subfolder through josh, as explain |
| 84 | +in "Getting Started". |
| 85 | + |
| 86 | +Instead of just the name of the subfolder, though, we also use the `:workspace=` filter: |
| 87 | + |
| 88 | +```shell |
| 89 | +{{#include workspaces.t:clone_workspace}} |
| 90 | +``` |
| 91 | + |
| 92 | +Looking into the newly cloned workspace, we see our expected files and the history containing the |
| 93 | +only relevant commit. |
| 94 | + |
| 95 | +--- |
| 96 | +**NOTE** |
| 97 | + |
| 98 | +Josh allows us to create a workspace out of any directory, even one that doesn't exist yet. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +### Adding workspace.josh |
| 103 | + |
| 104 | +The workspace.josh file describes how folders from the central repository (real\_repo.git) |
| 105 | +should be mapped to the workspace repository. |
| 106 | + |
| 107 | +Let's create one with the relevant components. |
| 108 | +First, the library we depend on: |
| 109 | + |
| 110 | +```shell |
| 111 | +{{#include workspaces.t:library}} |
| 112 | +``` |
| 113 | + |
| 114 | +We decided to map library1 to modules/lib1 in the workspace. |
| 115 | +After pushing and fetching the result, we se that it has been succesfully mapped by josh. |
| 116 | + |
| 117 | +One suprising thing is the history: our "mapping" commit became a merge commit! |
| 118 | +This is because josh needs to merge the history of the module we want to map into the |
| 119 | +repository of the workspace. |
| 120 | +After this is done, all commit will be present in both of the histories. |
| 121 | + |
| 122 | +--- |
| 123 | +**NOTE** |
| 124 | + |
| 125 | +`git sync` is a utility provided with josh which will push contents, and, if josh tells |
| 126 | +it to, fetch the transformed result. Otherwise, it works like git push. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +By the way, what does the history look like on the real\_repo ? |
| 131 | + |
| 132 | +```shell |
| 133 | +{{#include workspaces.t:real_repo}} |
| 134 | +``` |
| 135 | + |
| 136 | +We can see the newly added commit for workspace.josh in application1, and as expected, |
| 137 | +no merge here. |
0 commit comments