diff --git a/assets/css/extended/dlcols.css b/assets/css/extended/dlcols.css new file mode 100644 index 0000000..44075d7 --- /dev/null +++ b/assets/css/extended/dlcols.css @@ -0,0 +1,7 @@ +/* Side-by-side code columns, used by the dlcols/dlcol shortcodes. */ +.dlcols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; align-items: start; margin: 1rem 0; } +.dlcols-single { grid-template-columns: minmax(0, 1fr); } +.dlcols > div { min-width: 0; } +.dlcols pre, .dlcols code { font-size: 0.72rem; line-height: 1.4; } +.dlcols pre { overflow-x: auto; white-space: pre; } +@media (max-width: 600px) { .dlcols { grid-template-columns: 1fr; } } diff --git a/content/posts/adjusted-branch-unlocked/cover.webp b/content/posts/adjusted-branch-unlocked/cover.webp new file mode 100644 index 0000000..7f8a054 --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/cover.webp @@ -0,0 +1 @@ +/annex/objects/MD5E-s71700--6c3bca810b1c9e621130fb7ca69d22f4.webp diff --git a/content/posts/adjusted-branch-unlocked/index.md b/content/posts/adjusted-branch-unlocked/index.md new file mode 100644 index 0000000..bfdef51 --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/index.md @@ -0,0 +1,950 @@ +--- +title: 'A guide to the adjusted branch (unlocked)' +date: 2026-11-04T12:00:00+01:00 +author: +- Jiameng Wu +tags: +- DataLad +- git-annex +- Windows +- adjusted branch +cover: + image: cover.webp + alt: An orange tree branch with whole oranges and, grafted onto its tip, one peeled orange. + relative: true +description: > + How git-annex's adjusted branch works on Windows, where resetting it breaks, and how to test for it, with every example run on Linux and Windows side by side. +showToc: true +hidemeta: false +disableHLJS: true +disableShare: false +hideSummary: false +--- + +On Windows, every DataLad dataset, unless created with `--no-annex`, lives on an **adjusted branch**. To see why and learn how to work with it, it helps to start with what [git-annex](https://git-annex.branchable.com/) does on Linux and then understand how it is _adjusted_ for Windows. + +This guide provides minimal examples that follow each other and compare the two systems side by side: the default branch (`master` in this post) on Linux, and the adjusted branch on Windows. To run them yourself, download the script for [Linux](story-linux.sh) or for [Windows](story-windows.sh) (for Git Bash). Versions used: git-annex 10.20261026 and DataLad 1.8.0 on both machines, with git 2.43.0 on Linux and git 2.56.0 in Git Bash on Windows 11. + +## Lock and unlock + +Version control for data has to solve one key challenge: keeping every version of large files without making the history large. git is built for source code, small text files whose every version it stores in full; for data, that does not scale. git-annex therefore keeps the content out of git. An **annexed file** lives in three places: + +- the **annex store**, `.git/annex/objects/`, holds the content, read-only and named by its **key** (git-annex's name for the object encoding the size in bytes and the **checksum**, a fingerprint of the content), e.g. `MD5E-s8--f75b….bin`. _Each version of the file is an object of its own._ +- the **work tree** (what you see on disk) holds a **symlink** (a special file that stores the path to another file and thereby provides _an alternative access path without duplicating the target's content_) to the object in the annex store, e.g. `.git/annex/objects/.../MD5E-s8--f75b….bin`. +- **git** records only the symlink, never the content, in a commit / on a branch [^fn:git-space]. + +An annexed file stored this way is **locked**: reading is instantaneous and at no cost, since the filesystem simply follows the symlink to the content; writing, however, is prohibited and fails with `Permission denied`, so a stored version of a file is never changed or lost (unless intentionally dropped). To write, you **unlock** the file: git-annex replaces the symlink in the work tree with a writable copy, so one copy stays put while the other is modified. `datalad save` then stores the modification as a new object in the annex store, replaces the file in the work tree with a symlink that points to the new object, commits the new symlink to git, and thereby locks the file again. The old object stays, and checking out an earlier commit brings it back. + +On Windows, git-annex does not use symlinks. Instead, it uses a **path-text file**: a regular file holding the same path as plain text. Unlike a symlink, the filesystem cannot follow it: a program that opens it reads the path, not the content. So the content in the annex store is not reachable from the work tree: even reading a file would first require unlocking it, i.e. copying it into the work tree, which takes time and an extra step for every file you want to open. To make reading instantaneous again, git-annex unlocks every annexed file at once, on a dedicated branch, `adjusted/master(unlocked)`[^fn:modes], which `datalad create` checks out by default. The price is space: each annexed file is on disk twice, once in the annex store and once in the work tree. + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ # create stays on master +$ datalad create repo && cd repo +create(ok): /tmp/…/repo (dataset) + +$ echo "content" > file.bin +$ datalad save -m "add file" +add(ok): file.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # a symlink to the read-only content +$ ls -l file.bin +lrwxrwxrwx 116 file.bin -> .git/annex/objects/X2/Zj/MD5E-s8--f75b….bin/MD5E-s8--f75b….bin + +$ # git records a symlink (mode 120000) +$ git ls-tree HEAD file.bin +120000 blob af2b030… file.bin + +$ # reading follows the symlink to the content +$ cat file.bin +content + +$ # unlock: symlink -> writable copy +$ datalad unlock file.bin +[INFO] Unlocking files +[INFO] Recording unlocked state in git +[INFO] Completed unlocking files +unlock(ok): file.bin (file) + +$ ls -l file.bin +-rw-r--r-- 8 file.bin + +$ # staged as a typechange +$ git status +On branch master +Changes to be committed: + (use "git restore --staged ..." to unstage) + typechange: file.bin + +$ echo "new content" > file.bin +$ datalad save -m "edit file" +add(ok): file.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # save: new read-only object, new symlink +$ ls -l file.bin +lrwxrwxrwx 118 file.bin -> .git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ # create checks out the adjusted branch +$ datalad create repo && cd repo +[INFO] Detected a filesystem without fifo support. +[INFO] Disabling ssh connection caching. +[INFO] Detected a crippled filesystem. +[INFO] Entering an adjusted branch where files are unlocked as this filesystem does not support locked files. +[INFO] Switched to branch 'adjusted/master(unlocked)' +[INFO] +create(ok): C:\…\repo (dataset) + +$ echo "content" > file.bin +$ datalad save -m "add file" +add(ok): file.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # a regular, writable file with the content +$ ls -l file.bin +-rw-r--r-- 8 file.bin + +$ # git records a regular file (mode 100644) +$ git ls-tree HEAD file.bin +100644 blob a21bb0d… file.bin + +$ # reading the copy gives the content +$ cat file.bin +content + +$ # unlock has nothing to do, no "unlock(ok)" +$ datalad unlock file.bin +[INFO] Unlocking files +[INFO] Completed unlocking files + +$ ls -l file.bin +-rw-r--r-- 8 file.bin + +$ # nothing changed +$ git status +On branch adjusted/master(unlocked) +nothing to commit, working tree clean + +$ echo "new content" > file.bin +$ datalad save -m "edit file" +add(ok): file.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # a regular file with the new content +$ ls -l file.bin +-rw-r--r-- 12 file.bin +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +## master & adjusted/master(unlocked) + +Is the adjusted branch a different kind of history? Not really. A **commit** is a snapshot of all files plus a reference to its parent commit; following the parents back gives the history. A **branch** is just a bookmark: a name that points to one commit and moves forward whenever you commit on it. **HEAD** marks what you have checked out: it points to a branch, and through it to that branch's newest commit, whose snapshot your work tree shows. **`master`** (or `main`) is the default branch git checks out when a new repository is created. + +The **adjusted branch**, `adjusted/master(unlocked)`, is a branch like any other. It points to one commit, "git-annex adjusted branch", whose parent is the tip of `master`, its **corresponding branch**. This **adjusting commit** changes only how git records the annexed files: from a symlink (mode `120000`, with the path to the object as content) to a regular file (mode `100644`, with a **pointer** as content, a short text naming the object by its key). The work tree holds yet something else: an **unlocked** file, the content itself as a writable copy (unless the content is dropped). + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ # HEAD is your last commit +$ git log --oneline --decorate --summary -2 +6e02b1a (HEAD -> master) edit file +d7f438d add file + create mode 120000 file.bin + +$ # only master +$ git branch + git-annex +* master +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ # HEAD is the adjusting commit: +$ # it turns the symlink into a file; +$ # your last commit is below it +$ git log --oneline --decorate --summary -3 +6c1191a (HEAD -> adjusted/master(unlocked)) git-annex adjusted branch + mode change 120000 => 100644 file.bin +95790da (master) edit file +500fb52 add file + create mode 120000 file.bin + +$ # on the adjusted branch, master next to it +$ git branch +* adjusted/master(unlocked) + git-annex + master +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +`master` can still be checked out on Windows, but its annexed files are path-text files: + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ # already on master, the symlink is followed +$ cat file.bin +new content +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ # check out master +$ git checkout master +Switched to branch 'master' + +$ # a path-text file +$ cat file.bin +.git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin + +$ # 118 bytes (the path), not 12 (content) +$ ls -l file.bin +-rw-r--r-- 118 file.bin + +$ # git records 120000 (symlink)! +$ git ls-tree HEAD file.bin +120000 blob 4488793… file.bin + +$ # back on the adjusted branch: content +$ git checkout "adjusted/master(unlocked)" +Switched to branch 'adjusted/master(unlocked)' + +$ cat file.bin +new content +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +On Windows `core.symlinks` is `false`, so git creates no symlinks, yet it keeps recording mode `120000`: the history stays the same as on Linux. To tell whether such a file was modified, git compares its text with the recorded path. + +| on Windows | `master` | `adjusted/master(unlocked)` | +|---|---|---| +| git records | mode `120000` (symlink) and the object's path: `.git/annex/objects/…//` | mode `100644` (regular file) and a pointer: `/annex/objects/` | +| work tree gets | a path-text file | an unlocked file | + +{{< dldetails summary="Under the hood: how does git-annex place the content in the work tree?" id="the-clean-and-smudge-filter" >}} +{{% dlmd %}} +It takes two git mechanisms: a filter that git runs on every file passing between the work tree and the repository, and hooks that git runs after a checkout or merge. +{{% /dlmd %}} + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ # the filter is set up here too ... +$ git check-attr filter -- file.bin +file.bin: filter: annex + +$ cat .git/info/attributes + +* filter=annex + +$ git config --get-regexp '^filter\.annex' +filter.annex.smudge git-annex smudge -- %f +filter.annex.clean git-annex smudge --clean -- %f +filter.annex.process git-annex filter-process + +$ ls .git/hooks | grep -v sample +post-checkout +post-merge +post-receive +pre-commit +pre-push + +$ # ... but git stores a symlink: +$ # the filter has nothing to do +$ git cat-file -p :file.bin +.git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin + +$ cat file.bin +new content +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ # every path goes through the annex filter +$ git check-attr filter -- file.bin +file.bin: filter: annex + +$ cat .git/info/attributes + +* filter=annex + +$ git config --get-regexp '^filter\.annex' +filter.annex.smudge git-annex smudge -- %f +filter.annex.clean git-annex smudge --clean -- %f +filter.annex.process git-annex filter-process + +$ # hooks run "git annex smudge --update" +$ ls .git/hooks | grep -v sample +post-checkout +post-merge +post-receive +pre-commit +pre-push + +$ # git stores a pointer, +$ # git-annex put the content on disk +$ git cat-file -p :file.bin +/annex/objects/MD5E-s12--f8a6….bin + +$ cat file.bin +new content +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +{{% dlmd %}} +- **clean** runs on `git add`: it moves the content into the annex and hands git the pointer. +- **smudge** runs on checkout. git-annex's smudge filter does not write the content: it writes the pointer and notes the file, and the hook below fills in the content right after the checkout, if the content is present. (Large files would otherwise pass through git's memory.) + +Three pieces make this work, and `git annex init` writes all three: + +1. the **driver** in `.git/config` (`filter.annex.*`): *how* to run the filter; +2. the **assignment** in `.git/info/attributes` (`* filter=annex`): *which paths* use it; +3. the **hooks** in `.git/hooks/`: `post-checkout` and `post-merge` run `git annex smudge --update`, which replaces the pointers the filter wrote with the content. + +A driver without an assignment is never called. +To check a repository, ask git (`git check-attr filter -- ` prints `annex` or `unspecified`) rather than reading `.git/config`. + +The same pieces exist on Linux, but on `master` files are locked and git records symlinks, so the filter has nothing to do. +{{% /dlmd %}} +{{< /dldetails >}} + +## How your work reaches `master` + +So on Windows, you work on the adjusted branch: on `master`, your annexed files are path-text files, not your data. But only what reaches `master` counts, because `master` is what gets published; anything else can be lost. So how does your work get there? + +To carry your work over, git-annex keeps a third **ref** (a named reference to a commit, like a branch or HEAD): `refs/basis/adjusted/master(unlocked)`, `basis` for short. It records which `master` commit the adjusted branch was built from, separately from `master`, because `master` can change under its feet, for example when someone pushes into your repository. Every `datalad save` ends with a local sync (`git annex sync --no-push --no-pull`), in four steps: + +1. DataLad stores the content as a new object in the annex store and commits a pointer to that object on the adjusted branch. +2. git-annex replays this commit on top of `basis`, recording the file as a symlink, as on Linux. +3. `basis` moves to the replayed commit, and `master` is set to the same commit. +4. git-annex makes a new adjusting commit on top. It takes your tree as it is, so the unlocked file in your work tree stays untouched. + +git-annex only replays commits that come after an adjusting commit; that becomes important when you reset. + +![The local sync during datalad save: replay on top of basis, master follows, new adjusting commit on top](sync.svg) + +So after a sync, `HEAD` is a fresh adjusting commit, not your last commit, and `HEAD~1` is the tip of `master`. +A plain `git commit` works too, but it lands on the adjusted branch, on top of the adjusting commit, and reaches `master` only at the next sync: an `update`, a `push`, or a `save` that commits something. So stick to `datalad save`. + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ # only master: your commits +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ +6e02b1a (master) edit file +d7f438d add file +99622d4 [DATALAD] new dataset +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ # master and basis on your last commit, +$ # the adjusted branch one commit above +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ +6c1191a (adjusted/master(unlocked)) git-annex adjusted branch +95790da (master, refs/basis/adjusted/master(unlocked)) edit file +500fb52 add file +07b40fc [DATALAD] new dataset +0cf32cf commit before entering adjusted branch +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +`push` runs the same local sync as `save`, then publishes only `master` and `git-annex`: the adjusted branch and `basis` never leave your machine, and a collaborator on Linux sees an ordinary dataset. + +`update` does more. On Linux, `datalad update --how=merge` is a plain `git merge` of `origin/master`. On Windows, it runs `git annex sync --pull`, in three steps: + +1. As in a `save`, commits on the adjusted branch that have not reached `master` yet are replayed on top of `basis`, and `master` follows, unless it has moved on its own. +2. If your local `master` has moved on its own, its commits are merged on top of `basis`, and `master` is set to the result, something a `save` never does. +3. The sibling's commit is merged on top of `basis`, not into the adjusted branch, where the unlocked files would cause needless merge conflicts. `basis` and `master` move to the merge result, and this time git-annex does not reuse your tree: the incoming files are not in it yet, and in `basis` they are recorded as symlinks. So it builds the new adjusting commit afresh from `basis`, recording every one of them as a pointer instead. + +![What datalad update does on an adjusted branch: your commit replayed onto basis, master's own commit and the sibling's commit merged on top of basis, a new adjusting commit built from basis](sync-update.svg) + +## Resetting on the adjusted branch + +To me, being able to go back and rewrite history is the whole point of version control. +If you only ever move forward, a digital lab notebook serves you as well as git or DataLad. +Because every decision can be undone, you can try things and take wrong turns without fear. +In a team, reset is also how you adopt history your collaborators rewrote: a merge would keep the discarded commits, and your next `push` would bring them right back. + +On `master` on Linux, going back is a single `git reset`. On the adjusted branch, it is where things truly break and what led me to write this guide. + +### What happens with a plain `git reset --hard` on the adjusted branch? + +Say you save some data, then accidentally overwrite it with junk, and you want the junk commit gone: + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ echo "data" > data.bin +$ datalad save -m "add data" +add(ok): data.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # unlock to modify +$ datalad unlock data.bin +[INFO] Unlocking files +[INFO] Recording unlocked state in git +[INFO] Completed unlocking files +unlock(ok): data.bin (file) + +$ echo "junk" > data.bin +$ datalad save -m "overwrite with junk" +add(ok): data.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # drop the junk commit +$ git reset --hard HEAD~1 +HEAD is now at 43d524e add data + +$ # data again +$ cat data.bin +data + +$ # the junk commit is gone +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +43d524e (master) add data +6e02b1a edit file +d7f438d add file +99622d4 [DATALAD] new dataset +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ echo "data" > data.bin +$ datalad save -m "add data" +add(ok): data.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # always unlocked +$ echo "junk" > data.bin +$ datalad save -m "overwrite with junk" +add(ok): data.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # drop the last commit with HEAD~1? +$ git reset --hard HEAD~1 +HEAD is now at d56eacd overwrite with junk + +$ # nope! HEAD~1 is master's junk commit: +$ # only the adjusting commit is gone +$ # drop one more? +$ git reset --hard HEAD~1 +HEAD is now at cf4c030 add data + +$ # still not data: master's path text +$ cat data.bin +.git/annex/objects/f3/2G/MD5E-s5--6137….bin/MD5E-s5--6137….bin + +$ # master and basis still on the junk commit, +$ # the adjusted branch below them +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +d56eacd (master, refs/basis/adjusted/master(unlocked)) overwrite with junk +cf4c030 (adjusted/master(unlocked)) add data +95790da edit file +500fb52 add file +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +The first reset removed git-annex's adjusting commit, and with it the unlocked files in your work tree. +Every commit below it is a `master` commit, which records annexed files as symlinks, so no matter how far back you reset, an annexed file only ever becomes a path-text file (the content itself is still safe in the annex store). +Meanwhile neither `basis` nor `master` has moved: both still point at the commit you meant to discard. And you are still on `adjusted/master(unlocked)`. + +So you give up on getting the content back to the work tree and keep working: + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ # data is back, keep working +$ echo "precious" > precious.bin +$ datalad save -m "add precious data" +add(ok): precious.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # "add precious data" on top of "add data" +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +b868b97 (master) add precious data +43d524e add data +6e02b1a edit file +d7f438d add file + +$ git log --all --oneline --no-decorate --grep "add precious data" +b868b97 add precious data + +$ ls +data.bin +file.bin +precious.bin +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ # keep working +$ echo "precious" > precious.bin +$ datalad save -m "add precious data" +add(ok): precious.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # a new adjusting commit on the junk; +$ # "add precious data" is not in master +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +0059e08 (adjusted/master(unlocked)) git-annex adjusted branch +d56eacd (master, refs/basis/adjusted/master(unlocked)) overwrite with junk +cf4c030 add data +95790da edit file + +$ # ... nor on any branch +$ git log --all --oneline --no-decorate --grep "add precious data" + +$ # precious.bin is in the adjusting commit, +$ # and so is data.bin's way back to data +$ git log -1 --stat --oneline --no-decorate +0059e08 git-annex adjusted branch + data.bin | 2 +- + precious.bin | 1 + + 2 files changed, 2 insertions(+), 1 deletion(-) + +$ # precious.bin is still on disk, for now +$ ls +data.bin +file.bin +precious.bin +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +`datalad save` reports `ok`, but your new commit is nowhere. +As said above, git-annex only replays commits made on top of an adjusting commit, and the first reset removed it, so your new commit is skipped. git-annex still puts a new adjusting commit on top of `basis`, which still holds the commit you meant to discard, but not the one you meant to keep. That new adjusting commit takes the tree of your last commit as it is, so by mistake it includes your new file, as well as the change that undid the discarded commit. Your file is still on disk, for now, but its commit is already gone from every branch. + +Meanwhile a collaborator pushes a commit to the sibling, and you `update` as usual: + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ datalad update --how=merge -s sibling +[INFO] Fetching updates for Dataset(/tmp/…/repo) +[INFO] Start enumerating objects +[INFO] Start counting objects +[INFO] Start compressing objects +merge(ok): . (dataset) [Merged sibling/master] +update.annex_merge(ok): . (dataset) [Merged annex branch] +update(ok): . (dataset) +action summary: + merge (ok: 1) + update (ok: 1) + update.annex_merge (ok: 1) + +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +d7f2b7f (master) add theirs +b868b97 add precious data +43d524e add data +6e02b1a edit file + +$ # precious.bin is still there +$ ls +data.bin +file.bin +precious.bin +theirs.bin + +$ # data, as after the reset +$ cat data.bin +data +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ datalad update --how=merge -s sibling +[INFO] Fetching updates for Dataset("C:\…\repo") +[INFO] Start enumerating objects +[INFO] Start counting objects +[INFO] Start compressing objects +update.annex_sync(ok): . (dataset) [Ran git-annex-sync] +update(ok): . (dataset) +action summary: + update (ok: 1) + update.annex_sync (ok: 1) + +$ # their commit on top of the junk, +$ # a new adjusting commit on top; +$ # no precious data anywhere +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +8c3026a (adjusted/master(unlocked)) git-annex adjusted branch +1e1845c (master, refs/basis/adjusted/master(unlocked)) add theirs +d56eacd overwrite with junk +cf4c030 add data + +$ # precious.bin is gone: the adjusted +$ # branch was rebuilt from basis +$ ls +data.bin +file.bin +theirs.bin + +$ # the junk is back: master never dropped it +$ cat data.bin +junk +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +Your new file is gone, and the discarded commit is back. That's because `update` builds the adjusted branch afresh from `basis`, which has never seen your new file or the reset. And that's why the adjusted branch is considered _disposable_. + +The rule: **never move the adjusted branch backwards.** + +Even discarding an *unsaved* edit has a catch: + + +{{< dlcols >}} +{{% dlcol title="Linux" %}} +```console +$ echo "content" > notes.bin +$ datalad save -m "add notes" +add(ok): notes.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ datalad unlock notes.bin +[INFO] Unlocking files +[INFO] Recording unlocked state in git +[INFO] Completed unlocking files +unlock(ok): notes.bin (file) + +$ echo "edited" > notes.bin +$ git reset --hard +HEAD is now at fbded2e add notes + +$ git status +On branch master +nothing to commit, working tree clean + +$ # the content: git restored the symlink +$ cat notes.bin +content + +$ git checkout -- . +$ cat notes.bin +content +``` +{{% /dlcol %}} +{{% dlcol title="Windows" %}} +```console +$ echo "content" > notes.bin +$ datalad save -m "add notes" +add(ok): notes.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ echo "edited" > notes.bin +$ git reset --hard +HEAD is now at 9363553 git-annex adjusted branch + +$ # git calls the work tree clean ... +$ git status +On branch adjusted/master(unlocked) +nothing to commit, working tree clean + +$ # ... but the file holds the pointer: +$ # no hook ran after the reset +$ cat notes.bin +/annex/objects/MD5E-s8--f75b….bin + +$ # the post-checkout hook fills it in +$ git checkout -- . + +$ # the content is back +$ cat notes.bin +content +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +The content is still in the annex, but the work tree holds the pointer. +`git reset` writes back what git recorded, the pointer, but unlike a checkout it runs no hook, so git-annex never gets the chance to place the content (see [how git-annex places the content in the work tree](#the-clean-and-smudge-filter) above). +Beware: `git status`, `git diff` and `datalad status` all call such a file clean, because the pointer matches what is committed; only looking at the content shows the problem. +The reliable way to bring the content back is `git checkout -- .`: it fires the `post-checkout` hook, which runs `git annex smudge --update` and places the content.[^fn:timing] + +### How to reset the adjusted branch correctly + +If you have followed the tale of the adjusted branch so far, you probably already have an idea how to do a proper reset on Windows. Here is the recipe[^fn:synced-reset]: + +1. check out the corresponding branch: `git checkout master` +2. reset as usual: `git reset --hard ` +3. rebuild the adjusted branch: `git annex adjust --unlock --force` + + +{{< dlcols single="true" >}} +{{% dlcol title="Windows" %}} +```console +$ # leave the adjusted branch +$ git checkout master +Switched to branch 'master' + +$ # reset the real history to before the junk +$ git reset --hard ':/add data' +HEAD is now at cf4c030 add data + +$ # rebuild the adjusted branch from the reset master +$ git annex adjust --unlock --force +adjust +Switched to branch 'adjusted/master(unlocked)' +ok + +$ git branch +* adjusted/master(unlocked) + git-annex + master + +$ # master and basis are reset, the adjusted branch on top of them +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -3 +1444cdf (adjusted/master(unlocked)) git-annex adjusted branch +cf4c030 (master, refs/basis/adjusted/master(unlocked)) add data +95790da edit file + +$ # precious.bin does not come back: it never reached master +$ ls +data.bin +file.bin + +$ # but junk is gone! +$ cat data.bin +data +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +DataLad does these steps in `datalad update --how=reset`, to reset to the sibling's state; it works on adjusted branches since DataLad 1.6.5. + +## Dos and don'ts + +| | do | don't | +|---|---|---| +| edit files | on `adjusted/master(unlocked)` | on `master` (path-text files, not data) | +| commit | `datalad save` | `git commit` (reaches `master` only at the next sync) | +| discard unsaved edits | `git reset --hard`, then `git checkout -- .` | stop after `git reset --hard` (pointers, not content) | +| discard commits | reset `master`, then `git annex adjust --unlock --force`; or `datalad update --how=reset` | `git reset --hard HEAD~N` on `adjusted/master(unlocked)` | + +## Bonus: Why tests are skipped on Windows, and how to test the adjusted branch + +Many tests in DataLad's test suite are skipped on Windows, because they rely on properties that hold on Linux but not on Windows: + +1. `HEAD` is the tip of `master`, so `HEAD~1` is your previous commit (see [master & adjusted/master(unlocked)](#master--adjustedmasterunlocked)); +2. a commit is in `master` right away, without a sync (see [How your work reaches `master`](#how-your-work-reaches-master)); +3. a reset moves the history (see [Resetting on the adjusted branch](#resetting-on-the-adjusted-branch)); +4. annexed files are locked: read-only, behind a symlink (see [Lock and unlock](#lock-and-unlock)). + +Such a test fails on Windows for reasons unrelated to what it tests, and the easy fix is to skip it. So the code paths that only run on the adjusted branch end up with the fewest tests. + +**Strategy 1: write tests that do not rely on these properties.** Most of them can be avoided in the test itself, and then the same test holds on every branch: + +- Compare against the corresponding branch, not `HEAD`: on the adjusted branch `HEAD` is the adjusting commit, and its hash changes with every sync. Ask for the corresponding branch instead (`git rev-parse master`, or in DataLad `repo.get_corresponding_branch() or repo.get_active_branch()`). +- Name commits, do not count them from `HEAD`: `HEAD~1` is your previous commit on `master` and only the tip of `master` on the adjusted branch, as the first reset example shows. Use the commit's hash, or count from `master`. +- Build history with `datalad save`, not `git commit`: a plain commit on the adjusted branch reaches `master` only at the next sync, so a test that commits with git and then inspects `master` sees nothing. +- Check the outcome, not the report: tests assert on three levels, a result record saying `ok`, matching commit hashes, and the content being there, and each level alone can miss a problem. After `git reset --hard`, a file holding only the pointer passes the first two: the status is clean and the hashes match, and only reading the file shows that its content is missing. Can a test also pass the first and the third level, but not the second? Check out [the puzzle below](#a-puzzle-for-the-curious-mind). +- Where behavior really differs, assert the difference: ask `repo.is_managed_branch()` and assert what each kind of branch should do. DataLad's `test_unlock` gets halfway: on `master` it expects a saved file to be read-only and `datalad unlock` to report `ok`, but on the adjusted branch it only skips these checks instead of asserting what happens there. +- Make siblings bare: create a test's sibling with `git init --bare`, not `datalad create`. On Windows a created dataset has an adjusted branch of its own, and a `push` only moves its `master`: its work tree and its own next `save` never see the pushed commits, so the test ends up exercising the sibling's adjusted branch instead of what it meant to. + +**Strategy 2: run every test on three legs.** Instead of skipping, run each test on three legs, so that every part of it actually runs, on Linux too. The **locked** leg works directly on `master` and is the baseline that checks parity with git. The **adjusted** leg (`git annex adjust --unlock`, with symlinks on `master`) exercises the branch logic behind properties 1 to 3. The **no-symlink** leg is an adjusted branch with `core.symlinks=false`, as on Windows, and adds the consequences behind property 4: path-text files instead of locked files on `master`. On Windows only the locked leg is impossible, so only that leg is skipped. + +**Strategy 3: reproduce Windows on Linux, and know where that stops.** The no-symlink leg brings Windows' behavior to a Linux machine: set `core.symlinks=false` and enter the adjusted branch: + + +{{< dlcols single="true" >}} +{{% dlcol title="Linux" %}} +```console +$ # an adjusted branch with path text on master, as on Windows +$ cd .. && datalad create sim && cd sim +create(ok): /tmp/…/sim (dataset) + +$ git config core.symlinks false +$ git annex adjust --unlock +adjust +Switched to branch 'adjusted/master(unlocked)' +ok + +$ # write without unlocking +$ echo "kept" > kept.bin +$ datalad save -m "add kept" +add(ok): kept.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ echo "discarded" > discarded.bin +$ datalad save -m "add discarded" +add(ok): discarded.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # the correct reset from above, discarding the last commit ... +$ git checkout master +Switched to branch 'master' + +$ git reset --hard HEAD~1 +git-annex: git status will show kept.bin to be modified, since content availability has changed and git-annex was unable to update the index. This is only a cosmetic problem affecting git status; git add, git commit, etc won't be affected. To fix the git status display, you can run: git-annex restage +HEAD is now at fb05db2 add kept + +$ # ... fails on Linux, while it works on Windows +$ git annex adjust --unlock --force +adjust +error: Your local changes to the following files would be overwritten by checkout: + kept.bin +Please commit your changes or stash them before you switch branches. +Aborting +failed +adjust: 1 failed +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +With this setup, most of this post reproduces on Linux: the adjusting commit, `basis`, path-text files on `master`, the pointer after a reset and the swallowed `save`. One thing does not: the correct reset in the example above fails here, with the "git-annex restage" warning as the first sign. Here is what happens: + +1. git checks whether a path-text file on `master` was modified, for example in `git status`, `git reset --hard` or a checkout, and to do so passes it through git-annex's filter. +2. git-annex finds the key in the path text and, if the content is present, puts it into the file. +3. The file now holds the content, but git recorded the symlink's path, so git calls the file modified. + +On Windows, step 2 fails: git keeps the file open during step 2, Windows does not replace an open file, and git-annex ignores the error. The file stays a path-text file, and nothing is modified. + +In this Linux setup, the same replacement also breaks two more steps of this post that work on Windows: checking out the adjusted branch again from `master`, and `datalad update` after the resets, so the data loss on `update` cannot be replayed on Linux either. Leave these to Windows CI. A FAT-formatted drive on Linux should behave the same, since Linux replaces open files on any filesystem; I have not tested that. + +| | Linux | Windows | +|---|---|---| +| locked | yes | no: skip this leg | +| adjusted | yes, with `git annex adjust --unlock` | yes | +| no-symlink | yes, with `core.symlinks=false`; path text replaced by present content: expected failure | yes | + +In short: skip a test only where its case cannot even be set up, which is only the locked leg on Windows. Where a case passes on Windows but fails on the no-symlink leg on Linux, mark it as an expected failure (`pytest.mark.xfail(strict=False)`) there only, for example when `core.symlinks` is `false` on a system that is not Windows. The test then still runs and documents the gap, an unexpected pass is no error, and on Windows CI it is an ordinary test that has to pass. + +### A puzzle for the curious mind + +Say you checked out `master` by accident, saved a file there, checked out the adjusted branch again, saved another file, and pushed. Here is what you did on Windows: + + +{{< dlcols single="true" >}} +{{% dlcol title="Windows" %}} +```console +$ cd .. && datalad create puzzle && cd puzzle +$ git init -q --bare ../puzzle-sibling.git +$ datalad siblings add -s sibling --url ../puzzle-sibling.git +$ datalad push --to sibling +$ datalad clone ../puzzle-sibling.git ../collaborator + +$ # by accident on master +$ git checkout master +$ echo "first" > saved-on-master.bin +$ datalad save -m "save on master" + +$ # back to the adjusted branch +$ git checkout "adjusted/master(unlocked)" +$ echo "second" > saved-on-adjusted.bin +$ datalad save -m "save on the adjusted branch" +$ datalad push --to sibling +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +1. Which of the two files, `saved-on-master.bin` and `saved-on-adjusted.bin`, are in your work tree (with the adjusted branch checked out), on the adjusted branch, on `master`, and on the sibling? And for which of them does the sibling have the content? + +Then your collaborator adds a file and pushes it, and you `update`: + + +{{< dlcols single="true" >}} +{{% dlcol title="Windows" %}} +```console +$ # your collaborator adds a file and pushes it +$ datalad -C ../collaborator update --how=merge +$ echo "third" > ../collaborator/saved-on-sibling.bin +$ datalad -C ../collaborator save -m "save on sibling" +$ datalad -C ../collaborator push --to origin + +$ # you update +$ datalad update --how=merge -s sibling +``` +{{% /dlcol %}} +{{< /dlcols >}} + + +2. Which files are where now? +3. And after a second `datalad push`? + +{{< dldetails summary="Answers" >}} +{{% dlmd %}} +1. Work tree and adjusted branch: only `saved-on-adjusted.bin`. `master`: only `saved-on-master.bin`. The sibling records only `saved-on-master.bin`, but has the content only of `saved-on-adjusted.bin`. +2. Work tree, adjusted branch and `master`: all three files. The sibling records `saved-on-master.bin` and `saved-on-sibling.bin`, and has the content of `saved-on-adjusted.bin` and `saved-on-sibling.bin`. +3. All three files are everywhere, and the sibling has the content of all three. +{{% /dlmd %}} +{{< /dldetails >}} + +And the open question this guide leaves you with: how could the tests for `save`, `update` and `push` be improved to catch this? Consider contributing a pull request to [DataLad](https://github.com/datalad/datalad), and don't forget to tag me [@just-meng](https://github.com/just-meng) ;) + +[^fn:git-space]: If this sounds a little abstract or confusing to you, don't worry! A branch is just a name that points to a particular commit. When you check out / switch to a branch, git fills your work tree with files recorded by the commit the branch points to. +[^fn:modes]: `git annex adjust` has other modes too (`--lock`, `--fix`, `--hide-missing`, `--unlock-present`), which this guide does not cover. +[^fn:synced-reset]: With a git-annex from before its June 2026 fix ([avoid unnecessary synced branches](https://git-annex.branchable.com/todo/avoid_uncessary_synced_branches/)), also delete a leftover `synced/master` before rebuilding the adjusted branch, with `git branch -D synced/master`. Otherwise the next sync merges the discarded commits back in ([datalad#7772](https://github.com/datalad/datalad/issues/7772)). +[^fn:timing]: Sometimes a `git status` puts the content back too. git re-reads a file through git-annex's filter when the file is not older than the index, and git-annex then replaces the pointer with the content. On Linux, a reset usually writes the file and the index within the same moment, so the next `git status` restores the content. On Windows this fails for the same reason as described in the [bonus section](#bonus-why-tests-are-skipped-on-windows-and-how-to-test-the-adjusted-branch): git still has the file open. diff --git a/content/posts/adjusted-branch-unlocked/story-linux.sh b/content/posts/adjusted-branch-unlocked/story-linux.sh new file mode 100644 index 0000000..0e42eae --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/story-linux.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# The Linux side of "A guide to the adjusted branch (unlocked)". +# Every command shown in the post's Linux columns, in order. +# Lines marked "# setup" are not shown in the post but needed to run through. +# It works in a fresh temporary directory and leaves it behind for you to inspect. +set -eu +cd "$(mktemp -d)" +export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=init.defaultBranch GIT_CONFIG_VALUE_0=master # setup: start new repositories on master, as in the post + + +# --- 00-locked +# create stays on master +datalad create repo && cd repo +echo "content" > file.bin +datalad save -m "add file" +# a symlink to the read-only content +ls -l file.bin +# git records a symlink (mode 120000) +git ls-tree HEAD file.bin +# reading follows the symlink to the content +cat file.bin +# unlock: symlink -> writable copy +datalad unlock file.bin +ls -l file.bin +# staged as a typechange +git status +echo "new content" > file.bin +datalad save -m "edit file" +# save: new read-only object, new symlink +ls -l file.bin + +# --- 01-refs +# HEAD is your last commit +git log --oneline --decorate --summary -2 +# only master +git branch + +# --- 02-two-shapes +# already on master, the symlink is followed +cat file.bin + +# --- 03-filter +# the filter is set up here too ... +git check-attr filter -- file.bin +cat .git/info/attributes +git config --get-regexp '^filter\.annex' +ls .git/hooks | grep -v sample +# ... but git stores a symlink: +# the filter has nothing to do +git cat-file -p :file.bin +cat file.bin + +# --- 04-save +# only master: your commits +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ + +# --- 05-reset-view +echo "data" > data.bin +datalad save -m "add data" +# unlock to modify +datalad unlock data.bin +echo "junk" > data.bin +datalad save -m "overwrite with junk" +# drop the junk commit +git reset --hard HEAD~1 +# data again +cat data.bin +# the junk commit is gone +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master + +# --- 09-reset-below-basis +# data is back, keep working +echo "precious" > precious.bin +datalad save -m "add precious data" +# "add precious data" on top of "add data" +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +git log --all --oneline --no-decorate --grep "add precious data" +ls + +# --- 13-update-loss +git clone -q --bare . ../sibling.git # setup +git remote add sibling ../sibling.git # setup +datalad clone ../sibling.git ../theirs # setup +echo "theirs" > ../theirs/theirs.bin # setup +datalad -C ../theirs save -m "add theirs" # setup +datalad -C ../theirs push --to origin # setup +datalad update --how=merge -s sibling +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +# precious.bin is still there +ls +# data, as after the reset +cat data.bin + +# --- 06-reset-pointer +echo "content" > notes.bin +datalad save -m "add notes" +datalad unlock notes.bin +echo "edited" > notes.bin +git reset --hard +git status +# the content: git restored the symlink +cat notes.bin +git checkout -- . +cat notes.bin + + + + +# --- 14-simulate +# an adjusted branch with path text on master, as on Windows +cd .. && datalad create sim && cd sim +git config core.symlinks false +git annex adjust --unlock +# write without unlocking +echo "kept" > kept.bin +datalad save -m "add kept" +echo "discarded" > discarded.bin +datalad save -m "add discarded" +# the correct reset from above, discarding the last commit ... +git checkout master +git reset --hard HEAD~1 +set +e # setup +# ... fails on Linux, while it works on Windows +git annex adjust --unlock --force +set -e # setup diff --git a/content/posts/adjusted-branch-unlocked/story-windows.sh b/content/posts/adjusted-branch-unlocked/story-windows.sh new file mode 100644 index 0000000..d19b196 --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/story-windows.sh @@ -0,0 +1,175 @@ +#!/bin/bash +# The Windows side of "A guide to the adjusted branch (unlocked)". +# Every command shown in the post's Windows columns, in order, in Git Bash. +# Lines marked "# setup" are not shown in the post but needed to run through. +# It works in a fresh temporary directory and leaves it behind for you to inspect. +set -eu +cd "$(mktemp -d)" +export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=init.defaultBranch GIT_CONFIG_VALUE_0=master # setup: start new repositories on master, as in the post + + +# --- 00-locked +# create checks out the adjusted branch +datalad create repo && cd repo +echo "content" > file.bin +datalad save -m "add file" +# a regular, writable file with the content +ls -l file.bin +# git records a regular file (mode 100644) +git ls-tree HEAD file.bin +# reading the copy gives the content +cat file.bin +# unlock has nothing to do, no "unlock(ok)" +datalad unlock file.bin +ls -l file.bin +# nothing changed +git status +echo "new content" > file.bin +datalad save -m "edit file" +# a regular file with the new content +ls -l file.bin + +# --- 01-refs +# HEAD is the adjusting commit: +# it turns the symlink into a file; +# your last commit is below it +git log --oneline --decorate --summary -3 +# on the adjusted branch, master next to it +git branch + +# --- 02-two-shapes +# check out master +git checkout master +# a path-text file +cat file.bin +# 118 bytes (the path), not 12 (content) +ls -l file.bin +# git records 120000 (symlink)! +git ls-tree HEAD file.bin +# back on the adjusted branch: content +git checkout "adjusted/master(unlocked)" +cat file.bin + +# --- 03-filter +# every path goes through the annex filter +git check-attr filter -- file.bin +cat .git/info/attributes +git config --get-regexp '^filter\.annex' +# hooks run "git annex smudge --update" +ls .git/hooks | grep -v sample +# git stores a pointer, +# git-annex put the content on disk +git cat-file -p :file.bin +cat file.bin + +# --- 04-save +# master and basis on your last commit, +# the adjusted branch one commit above +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ + +# --- 05-reset-view +echo "data" > data.bin +datalad save -m "add data" +# always unlocked +echo "junk" > data.bin +datalad save -m "overwrite with junk" +# drop the last commit with HEAD~1? +git reset --hard HEAD~1 +# nope! HEAD~1 is master's junk commit: +# only the adjusting commit is gone +# drop one more? +git reset --hard HEAD~1 +# still not data: master's path text +cat data.bin +# master and basis still on the junk commit, +# the adjusted branch below them +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master + +# --- 09-reset-below-basis +# keep working +echo "precious" > precious.bin +datalad save -m "add precious data" +# a new adjusting commit on the junk; +# "add precious data" is not in master +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +# ... nor on any branch +git log --all --oneline --no-decorate --grep "add precious data" +# precious.bin is in the adjusting commit, +# and so is data.bin's way back to data +git log -1 --stat --oneline --no-decorate +# precious.bin is still on disk, for now +ls + +# --- 13-update-loss +git clone -q --bare . ../sibling.git # setup +git remote add sibling ../sibling.git # setup +datalad clone ../sibling.git ../theirs # setup +echo "theirs" > ../theirs/theirs.bin # setup +datalad -C ../theirs save -m "add theirs" # setup +datalad -C ../theirs push --to origin # setup +datalad update --how=merge -s sibling +# their commit on top of the junk, +# a new adjusting commit on top; +# no precious data anywhere +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +# precious.bin is gone: the adjusted +# branch was rebuilt from basis +ls +# the junk is back: master never dropped it +cat data.bin + +# --- 06-reset-pointer +echo "content" > notes.bin +datalad save -m "add notes" +echo "edited" > notes.bin +git reset --hard +# git calls the work tree clean ... +git status +# ... but the file holds the pointer: +# no hook ran after the reset +cat notes.bin +# the post-checkout hook fills it in +git checkout -- . +# the content is back +cat notes.bin + +# --- 10-reset-corresponding +# leave the adjusted branch +git checkout master +# reset the real history to before the junk +git reset --hard ':/add data' +# rebuild the adjusted branch from the reset master +git annex adjust --unlock --force +git branch +# master and basis are reset, the adjusted branch on top of them +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -3 +# precious.bin does not come back: it never reached master +ls +# but junk is gone! +cat data.bin + +# --- 15-puzzle +cd .. && datalad create puzzle && cd puzzle +git init -q --bare ../puzzle-sibling.git +datalad siblings add -s sibling --url ../puzzle-sibling.git +datalad push --to sibling +datalad clone ../puzzle-sibling.git ../collaborator +# by accident on master +git checkout master +echo "first" > saved-on-master.bin +datalad save -m "save on master" +# back to the adjusted branch +git checkout "adjusted/master(unlocked)" +echo "second" > saved-on-adjusted.bin +datalad save -m "save on the adjusted branch" +datalad push --to sibling + +# --- 16-puzzle-update +# your collaborator adds a file and pushes it +datalad -C ../collaborator update --how=merge +echo "third" > ../collaborator/saved-on-sibling.bin +datalad -C ../collaborator save -m "save on sibling" +datalad -C ../collaborator push --to origin +# you update +datalad update --how=merge -s sibling + diff --git a/content/posts/adjusted-branch-unlocked/sync-update.svg b/content/posts/adjusted-branch-unlocked/sync-update.svg new file mode 100644 index 0000000..1287383 --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/sync-update.svg @@ -0,0 +1,186 @@ + + What datalad update does on an adjusted branch, in three steps + + + + + + + + + + + adjusted/master(unlocked) + basis + master + dashed: only if master moved on its own + + + + + + + add theirs + fetched from the sibling + + + + edit file + edit file + edit file + + + + git-annex adjusted branch + add yours + not synced yet + + + + + + + + + saved on master + master moved on its own + + + + + add yours + + + + add yours + + + + + saved on master + + + + saved on master + merged + + + add yours + saved on master + + + + + + add theirs + + + + add theirs + merged + + + add theirs + + + + + + add yours + + + saved on master + + + add theirs + + + git-annex adjusted branch + new: built from basis + + + + + Before: your commit is not synced yet, master has one of + its own, and the sibling has a new one. + 1. Your commit is replayed on top of basis. master has + moved on its own, so it does not follow. + 2. master's own commit is merged on top of basis, + and master is set to the result. + 3. The sibling's commit is merged on top of basis, + and master follows. + The old adjusting commit is dropped; + a new one is built afresh from basis. + After: all three agree, with every commit in them. + diff --git a/content/posts/adjusted-branch-unlocked/sync.svg b/content/posts/adjusted-branch-unlocked/sync.svg new file mode 100644 index 0000000..389c567 --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/sync.svg @@ -0,0 +1,126 @@ + + The local sync during datalad save on an adjusted branch + + + + + + + + + + + adjusted/master(unlocked) + basis + master + + + + + + add file + add file + add file + edit file + edit file + edit file + + + + + git-annex adjusted branch + + + + + + + + + edit file again + your commit: pointer + copy from basis + + + + + edit file again + + + edit file again + copy: symlink, new hash + + + + + + edit file again + same commit as basis + + + + + + git-annex adjusted branch + new: your current tree + + + + + 1. Your commit, a pointer to the new object, is on the adjusted branch. + 2. git-annex replays it on top of basis (file as symlink). + 3. master is set to the same commit as basis. + 4. The old adjusting commit is dropped; a new one goes on top. + After: all three agree again. + diff --git a/layouts/shortcodes/dlcol.html b/layouts/shortcodes/dlcol.html new file mode 100644 index 0000000..ad69e01 --- /dev/null +++ b/layouts/shortcodes/dlcol.html @@ -0,0 +1,4 @@ +
+

{{ .Get "title" }}

+{{ .Inner }} +
diff --git a/layouts/shortcodes/dlcols.html b/layouts/shortcodes/dlcols.html new file mode 100644 index 0000000..a0f7c3e --- /dev/null +++ b/layouts/shortcodes/dlcols.html @@ -0,0 +1,3 @@ +
+{{ .Inner }} +
diff --git a/layouts/shortcodes/dldetails.html b/layouts/shortcodes/dldetails.html new file mode 100644 index 0000000..3a0cb99 --- /dev/null +++ b/layouts/shortcodes/dldetails.html @@ -0,0 +1,7 @@ +{{- /* A collapsible block. Unlike Hugo's built-in details shortcode, it takes +an id, so that a link can point to the block. Wrap Markdown content in +{{% dlmd %}}, see dlmd.html. */ -}} + +{{ .Get "summary" | markdownify }} +{{ .Inner }} + diff --git a/layouts/shortcodes/dlmd.html b/layouts/shortcodes/dlmd.html new file mode 100644 index 0000000..bbb27c1 --- /dev/null +++ b/layouts/shortcodes/dlmd.html @@ -0,0 +1,6 @@ +{{- /* Renders its content as Markdown inside a dldetails block. dldetails uses +the standard {{< >}} notation, which does not render its content as Markdown; +wrapping the Markdown parts in {{% dlmd %}} (Markdown notation) does. Without +the wrapper, raw Markdown shows up; using {{% dldetails %}} instead makes the +whole block disappear, without a build error. */ -}} +{{ .Inner }}