Skip to content

Commit 9782ee2

Browse files
committed
Add docs on symlink
1 parent f73ee00 commit 9782ee2

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ git-sync can also be configured to make a webhook call or exec a command upon
2525
successful git repo synchronization. The call is made after the symlink is
2626
updated.
2727

28+
## What it produces and why - the contract
29+
30+
git-sync has two required flags: `--repo`, which specifies which remote git
31+
repo to sync, and `--root` which specifies a working directory for git-sync,
32+
which presents an "API" of sorts.
33+
34+
The `--root` directory is _not_ the synced data.
35+
36+
Inside the `--root` directory git-sync stores the synced git state and other
37+
things. That directory may or may not respond to git commands - it's an
38+
implementation detail.
39+
40+
One of the things in that directory is a symlink (see the `--link` flag) to the
41+
most recently synced data. This is how the data is expected to be consumed,
42+
and is considered to be the "contract" between git-sync and consumers. The
43+
exact target of that symlink is an implementation detail, but the leaf
44+
component of the target (i.e. `basename "$(readlink <link>)"`) is the git hash
45+
of the synced revision. This is also part of the contract.
46+
47+
git-sync looks for changes in the remote repo periodically (see the `--period`
48+
flag) and will attempt to transfer as little data as possible and use as little
49+
disk space as possible (see the `--depth` and `--git-gc` flags), but this is
50+
not part of the contract.
51+
52+
### Why the symlink?
53+
54+
git checkouts are not "atomic" operations. If you look at the repository while
55+
a checkout is happening, you might see data that is neither exactly the old
56+
revision nor the new. git-sync "publishes" updates via the symlink to present
57+
an atomic interface to consumers. When the remote repo has changed, git-sync
58+
will fetch the data _without_ checking it out, then create a new worktree, then
59+
change the symlink to point to that new worktree.
60+
61+
git-sync does not currently have a no-symlink mode.
62+
2863
## Major update: v3.x -> v4.x
2964

3065
git-sync has undergone many significant changes between v3.x and v4.x. [See
@@ -139,6 +174,38 @@ DESCRIPTION
139174
git-sync can also be configured to make a webhook call upon successful git
140175
repo synchronization. The call is made after the symlink is updated.
141176
177+
CONTRACT
178+
179+
git-sync has two required flags:
180+
--repo: specifies which remote git repo to sync
181+
--root: specifies a working directory for git-sync
182+
183+
The root directory is not the synced data.
184+
185+
Inside the root directory, git-sync stores the synced git state and other
186+
things. That directory may or may not respond to git commands - it's an
187+
implementation detail.
188+
189+
One of the things in that directory is a symlink (see the --link flag) to
190+
the most recently synced data. This is how the data is expected to be
191+
consumed, and is considered to be the "contract" between git-sync and
192+
consumers. The exact target of that symlink is an implementation detail,
193+
but the leaf component of the target (i.e. basename "$(readlink <link>)")
194+
is the git hash of the synced revision. This is also part of the contract.
195+
196+
Why the symlink? git checkouts are not "atomic" operations. If you look
197+
at the repository while a checkout is happening, you might see data that is
198+
neither exactly the old revision nor the new. git-sync "publishes" updates
199+
via the symlink to present an atomic interface to consumers. When the
200+
remote repo has changed, git-sync will fetch the data _without_ checking it
201+
out, then create a new worktree, then change the symlink to point to that
202+
new worktree.
203+
204+
git-sync looks for changes in the remote repo periodically (see the
205+
--period flag) and will attempt to transfer as little data as possible and
206+
use as little disk space as possible (see the --depth and --git-gc flags),
207+
but this is not part of the contract.
208+
142209
OPTIONS
143210
144211
Many options can be specified as either a commandline flag or an environment

main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,38 @@ DESCRIPTION
21692169
git-sync can also be configured to make a webhook call upon successful git
21702170
repo synchronization. The call is made after the symlink is updated.
21712171
2172+
CONTRACT
2173+
2174+
git-sync has two required flags:
2175+
--repo: specifies which remote git repo to sync
2176+
--root: specifies a working directory for git-sync
2177+
2178+
The root directory is not the synced data.
2179+
2180+
Inside the root directory, git-sync stores the synced git state and other
2181+
things. That directory may or may not respond to git commands - it's an
2182+
implementation detail.
2183+
2184+
One of the things in that directory is a symlink (see the --link flag) to
2185+
the most recently synced data. This is how the data is expected to be
2186+
consumed, and is considered to be the "contract" between git-sync and
2187+
consumers. The exact target of that symlink is an implementation detail,
2188+
but the leaf component of the target (i.e. basename "$(readlink <link>)")
2189+
is the git hash of the synced revision. This is also part of the contract.
2190+
2191+
Why the symlink? git checkouts are not "atomic" operations. If you look
2192+
at the repository while a checkout is happening, you might see data that is
2193+
neither exactly the old revision nor the new. git-sync "publishes" updates
2194+
via the symlink to present an atomic interface to consumers. When the
2195+
remote repo has changed, git-sync will fetch the data _without_ checking it
2196+
out, then create a new worktree, then change the symlink to point to that
2197+
new worktree.
2198+
2199+
git-sync looks for changes in the remote repo periodically (see the
2200+
--period flag) and will attempt to transfer as little data as possible and
2201+
use as little disk space as possible (see the --depth and --git-gc flags),
2202+
but this is not part of the contract.
2203+
21722204
OPTIONS
21732205
21742206
Many options can be specified as either a commandline flag or an environment

0 commit comments

Comments
 (0)