Liking cljdoc? Tell your friends :D

Git

Here, we explore how poly works with git.

Let’s continue with our tutorial. The last thing we did in our tutorial was add build support.

We’ll start with the info command. We have had you run this command without explaining everything it outputs. Rerun info to see the current state of your workspace:

poly info
info

At the top, you’ll notice stable since: c91fdad (your git short-SHA will differ from our c91fdad). What does this mean? Let’s start from the beginning.

When you specify :commit when creating a Polylith workspace, poly executes these git commands on your behalf:

git init
git add .
git commit -m "Workspace created."

If you don’t specify :commit for the create workspace command, it is up to you to execute the above git commands (or the equivalent) manually.

Run git log from your example workspace root, and you’ll see something like:

commit c91fdad4a34927d9aacfe4b04ea2f304f3303282 (HEAD -> main)
Author: lisa <lisa@gmail.com>
Date:   Thu Sep 3 06:11:23 2020 +0200

    Workspace created.

This is the first and only commit for this git repository. Notice that the commit hash matches the short-SHA from the info command output: stable since: c91fdad. This first commit is considered the first stable point in time for this workspace.

The info command calculates what has changed since the current stable point in time.

Cursive users: If you followed our setup instructions, Cursive will automatically add new files to the git repository.

If all files have not been added to git yet, add them now:

git add --all

Look at the info command output again:

info

Notice that poly has marked all projects (command-line and development) and all bricks (user and cli) with a trailing * (asterisk), meaning they have changed after the current stable point in time (as described by stable since: c91fdad).

Let’s dig into how poly determines this. Run the diff command to see all files that have been added since the last commit:

poly diff

You should see output like this:

bases/cli/deps.edn
bases/cli/resources/cli/.keep
bases/cli/src/se/example/cli/core.clj
bases/cli/test/se/example/cli/core_test.clj
build.clj
components/user/deps.edn
components/user/resources/user/.keep
components/user/src/se/example/user/core.clj
components/user/src/se/example/user/interface.clj
components/user/test/se/example/user/interface_test.clj
deps.edn
development/src/dev/lisa.clj
projects/command-line/deps.edn
workspace.edn

We expect you are starting to see how poly decides to mark items as changed with the * (asterisk):

The poly tool knows that there are changes in:Because there are differences under dir:

command-line project

projects/command-line/

development project

development/

user brick

component/user/

cli brick

bases/cli/

Internally, the diff command runs:

git diff c91fdad4a34927d9aacfe4b04ea2f304f3303282 --name-only

If your workspace root isn’t the same as your git root, the diff command will internally strip away the workspace directory.

The workspace directory is available via poly get:ws-local-dir and will return nil if your workspace is at the git root.

When you created your workspace, poly created a .gitignore for you. Now is a good time to add more rules to /.gitignore if needed.

Add and commit any new and changed files:

git add --all
git commit -m "Created the user and cli bricks."

Have a look at our workspace repository commit history again:

git log --pretty=oneline

Your git SHAs will be different, but you’ll see something like:

e7ebe683a775ec28b7c2b5d77e01e79d48149d13 (HEAD -> main) Created the user and cli bricks.
c91fdad4a34927d9aacfe4b04ea2f304f3303282 Workspace created.

If you rerun the info command, it will return the same result as before. This is because you haven’t moved your stable point in time yet. We’ll dig into this in Tagging.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close