From 0872eb9d1ee870f31db4c4f7a34ca27c5a2864d1 Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Mon, 2 Nov 2026 22:23:28 +0100 Subject: [PATCH 1/7] add shortcodes for side-by-side code columns and collapsible blocks cols/col render two code columns next to each other (one full-width column with single="true"); details/md give a collapsible block whose content may hold both markdown and shortcodes. PaperMod's collapse markdownifies its content and so drops the HTML of nested shortcodes. --- layouts/shortcodes/col.html | 4 ++++ layouts/shortcodes/cols.html | 11 +++++++++++ layouts/shortcodes/details.html | 4 ++++ layouts/shortcodes/md.html | 1 + 4 files changed, 20 insertions(+) create mode 100644 layouts/shortcodes/col.html create mode 100644 layouts/shortcodes/cols.html create mode 100644 layouts/shortcodes/details.html create mode 100644 layouts/shortcodes/md.html diff --git a/layouts/shortcodes/col.html b/layouts/shortcodes/col.html new file mode 100644 index 0000000..ad69e01 --- /dev/null +++ b/layouts/shortcodes/col.html @@ -0,0 +1,4 @@ +
+

{{ .Get "title" }}

+{{ .Inner }} +
diff --git a/layouts/shortcodes/cols.html b/layouts/shortcodes/cols.html new file mode 100644 index 0000000..5d552b2 --- /dev/null +++ b/layouts/shortcodes/cols.html @@ -0,0 +1,11 @@ +
+{{ .Inner }} +
+ diff --git a/layouts/shortcodes/details.html b/layouts/shortcodes/details.html new file mode 100644 index 0000000..70311d7 --- /dev/null +++ b/layouts/shortcodes/details.html @@ -0,0 +1,4 @@ + +{{ .Get "summary" | markdownify }} +{{ .Inner }} + diff --git a/layouts/shortcodes/md.html b/layouts/shortcodes/md.html new file mode 100644 index 0000000..59448a1 --- /dev/null +++ b/layouts/shortcodes/md.html @@ -0,0 +1 @@ +{{ .Inner }} -- 2.54.1 From 434345799319137e20348933950e122ece59c6c9 Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Wed, 4 Nov 2026 14:57:58 +0100 Subject: [PATCH 2/7] add new post: a guide to the adjusted branch (unlocked) How git-annex's adjusted branch works on Windows, where resetting it breaks, and how to test for it. Every example comes from one story run on Linux and on Windows; story-linux.sh and story-windows.sh let readers replay it. --- .../posts/adjusted-branch-unlocked/cover.webp | 1 + .../posts/adjusted-branch-unlocked/index.md | 918 ++++++++++++++++++ .../adjusted-branch-unlocked/story-linux.sh | 119 +++ .../adjusted-branch-unlocked/story-windows.sh | 160 +++ .../adjusted-branch-unlocked/sync-update.svg | 186 ++++ .../posts/adjusted-branch-unlocked/sync.svg | 126 +++ 6 files changed, 1510 insertions(+) create mode 100644 content/posts/adjusted-branch-unlocked/cover.webp create mode 100644 content/posts/adjusted-branch-unlocked/index.md create mode 100644 content/posts/adjusted-branch-unlocked/story-linux.sh create mode 100644 content/posts/adjusted-branch-unlocked/story-windows.sh create mode 100644 content/posts/adjusted-branch-unlocked/sync-update.svg create mode 100644 content/posts/adjusted-branch-unlocked/sync.svg 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..8c0a630 --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/index.md @@ -0,0 +1,918 @@ +--- +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 lives on an **adjusted branch**. +It is a handful of git refs, a git filter, and one rule about which branch is the real one. +Once you know these, its surprises make sense. + +The examples below are one continuous story, cut into small pieces, each shown with its output side by side: a normal branch 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 & unlock + +A **locked** file is a read-only file that holds the content and sits in the annex store `.git/annex/objects/`, named by its **key** (git-annex's name for the object, e.g. `MD5E-s8--f75b….bin`: the size in bytes, `s8`, plus the **checksum**, a fingerprint of the content). The work tree only holds a **symlink** (a tiny file that just points to another path). Writing to it fails with `Permission denied`. `datalad unlock` replaces the symlink with a writable copy in the work tree. `datalad save` stores the edit as a new read-only object in the annex store and replaces the file in the work tree with the new symlink. The old object simply stays in the annex store and can be retrieved by checking out the associated commit. + +On Windows there is no such thing as a locked file, because symlinks don't work there (thus crippled filesystem). +A Windows user only ever sees normal, writable files in a DataLad dataset. +Instead, git-annex keeps two copies of each annexed file: one in `.git/annex/objects/`, and a writable one in the work tree. +Upon `datalad create`, git-annex automatically checks out an adjusted branch, `adjusted/master(unlocked)`. This is where the second copy lives. It is called **unlocked**[^fn:modes] because every annexed file in it is unlocked. So each annexed file is either dropped or on disk twice. + + +{{< cols >}} +{{% col 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 into the annex store, where the content is read-only +$ 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 + +$ # unlock replaces the symlink with a 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 + +$ # the symlink -> file switch is 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 stores the new content as a new read-only object and puts a new symlink in place +$ ls -l file.bin +lrwxrwxrwx 118 file.bin -> .git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin +``` +{{% /col %}} +{{% col title="Windows" %}} +```console +$ # create detects a crippled filesystem and checks out the adjusted branch by itself +$ 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 + +$ # 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) + +$ # still a regular file, now with the new content +$ ls -l file.bin +-rw-r--r-- 12 file.bin +``` +{{% /col %}} +{{< /cols >}} + + +## master & adjusted/master(unlocked) + +Does that mean the history is managed differently on the adjusted branch? 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 specific commit, "git-annex adjusted branch", whose parent is the tip of `master`, so its history is exactly `master`'s plus that one commit. git-annex made that commit, not you, and its only change is what `--summary` reports: `mode change 120000 => 100644` for every annexed file in the tree. `master` is called the adjusted branch's **corresponding branch**. + + +{{< cols >}} +{{% col title="Linux" %}} +```console +$ # HEAD is your last commit +$ git log --oneline --decorate --summary -2 +3ac59df (HEAD -> master) edit file +26ca99a add file + create mode 120000 file.bin + +$ # only master +$ git branch + git-annex +* master +``` +{{% /col %}} +{{% col title="Windows" %}} +```console +$ # HEAD is the "git-annex adjusted branch" commit: it turns the symlink into a regular 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 + +$ # adjusted branch checked out, master next to it +$ git branch +* adjusted/master(unlocked) + git-annex + master +``` +{{% /col %}} +{{< /cols >}} + + +Why is the adjusted branch necessary? Let's understand how `master` behaves on a crippled filesystem. + + +{{< cols >}} +{{% col title="Linux" %}} +```console +$ # already on master, the symlink is followed +$ cat file.bin +new content +``` +{{% /col %}} +{{% col title="Windows" %}} +```console +$ # leave the adjusted branch, switch to master +$ git switch master +Switched to branch 'master' + +$ # no symlink to follow, only a regular file that contains the literal path +$ cat file.bin +.git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin + +$ # a regular file of 118 bytes (the path), not 12 (the content) +$ ls -l file.bin +-rw-r--r-- 118 file.bin + +$ # git records 120000 (symlink), not 100644 (regular file)! +$ git ls-tree HEAD file.bin +120000 blob 4488793… file.bin + +$ # back to the adjusted branch: the content is there again +$ git switch "adjusted/master(unlocked)" +Switched to branch 'adjusted/master(unlocked)' + +$ cat file.bin +new content +``` +{{% /col %}} +{{< /cols >}} + + +Notice that git still records the mode `120000` (symlink) on `master` on Windows, but we just said that symlinks don't work here. On `master` with `core.symlinks=false` (set by git-annex), git cannot create the symlink, so it writes a regular file whose content is the link target path. It is not a broken symlink, it is not a symlink at all. This is why you cannot work on `master` on Windows: annexed files there contain a path, not your data. git keeps recording mode `120000` deliberately, so the history stays exactly as on Linux. To decide whether such a file was modified, git compares its content, the path text, with the recorded link target. + +| | `master` | `adjusted/master(unlocked)` | +|---|---|---| +| annexed files are | locked | unlocked | +| git mode | `120000` (symlink) | `100644` (regular file) | +| git stores | a **symlink target** (the object's path): `.git/annex/objects/…//` | a **pointer** (a small text that names the object by its key): `/annex/objects/` | +| read by | the operating system | git-annex, whose hooks put the content on disk | +| work tree gets | a symlink to the content; on Windows, a text file holding the path | a regular file with the content | + +{{< details summary="Under the hood: how does git-annex replace the pointer by its content?" id="the-clean-and-smudge-filter" >}} +{{% md %}} +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. +{{% /md %}} + + +{{< cols >}} +{{% col 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, so 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 +``` +{{% /col %}} +{{% col 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 + +$ # post-checkout and post-merge 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 +``` +{{% /col %}} +{{< /cols >}} + + +{{% md %}} +- **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 a normal branch files are locked and git stores symlinks, so the filter has nothing to do. +{{% /md %}} +{{< /details >}} + +## How your work reaches `master` + +You work on the adjusted branch, but only what reaches `master` counts; anything else can be lost. So how does your work get there? + +git-annex uses a third **ref** (a named reference to a commit, such as HEAD; a branch is one kind of ref) `refs/basis/adjusted/master(unlocked)`, to sync between the corresponding branch and the adjusted branch; for `datalad save` this is a purely local `git annex sync` (`--no-push --no-pull`). +`basis` records which `master` commit the adjusted branch was built from. +git-annex keeps this record separately because `master` itself can change under its feet, for example when someone pushes into your repository. +When you `datalad save` on the adjusted branch, this happens in order: + +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 to the object, 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. + +![The local sync during datalad save: replay on top of basis, master follows, new adjusting commit on top](sync.svg) + +So after a sync that carried something over, `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 with two caveats: it lands on the adjusted branch, on top of the adjusting commit, and reaches `master` only at the next sync (`save`, `update` or `push`); and on a normal branch it records a file you unlocked as unlocked (mode `100644`), while `datalad save` would have locked it again. So stick to `datalad save`. +git-annex only replays commits that come after an adjusting commit; that becomes important when you reset. + + +{{< cols >}} +{{% col title="Linux" %}} +```console +$ # only master: your commits +$ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ +3ac59df (master) edit file +26ca99a add file +f949e5b [DATALAD] new dataset +``` +{{% /col %}} +{{% col title="Windows" %}} +```console +$ # master and basis on your last commit, the adjusted branch one adjusting 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 +``` +{{% /col %}} +{{< /cols >}} + + +`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`, converting every symlink into an unlocked file. + +![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, personally, 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 a normal branch, going back is a single `git reset`. On the adjusted branch, it is where things truly break and what led me to writing 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: + + +{{< cols >}} +{{% col 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 544800b 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 +544800b (master) add data +3ac59df edit file +26ca99a add file +f949e5b [DATALAD] new dataset +``` +{{% /col %}} +{{% col 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 copy of the 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: the path to data's object, master's symlink form +$ 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 +``` +{{% /col %}} +{{< /cols >}} + + +The first reset removed git-annex's adjusting commit, and with it the unlocked copies in your work tree. +Every commit below it is a `master` commit, which records files as symlinks, so no matter how far back you reset, `data.bin` only ever holds the symlink's target path (the content itself is still safe in the annex store). +Meanwhile neither `basis` nor `master` has moved: both still point at the junk commit. And you are still on `adjusted/master(unlocked)`. + +So you give up on getting the content back to the work tree and keep working: + + +{{< cols >}} +{{% col 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 +9687243 (master) add precious data +544800b add data +3ac59df edit file +26ca99a add file + +$ git log --all --oneline --no-decorate --grep "add precious data" +9687243 add precious data + +$ ls +data.bin +file.bin +precious.bin +``` +{{% /col %}} +{{% col 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 top of master, junk included; "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 + +$ # ... and "add precious data" is on no branch at all +$ git log --all --oneline --no-decorate --grep "add precious data" + +$ # precious.bin sits inside the adjusting commit instead, and so does 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 +``` +{{% /col %}} +{{< /cols >}} + + +`datalad save` reports `ok`, but "add precious data" is nowhere. +git-annex only carries over commits made on top of an adjusting commit; the first reset removed it, so your new commit is skipped. git-annex still puts a new adjusting commit on top of `basis`, which holds the should-be-discarded junk commit but not the should-be-committed precious commit. That new adjusting commit takes the tree of your last commit as it is, so by mistake it includes `precious.bin`, as well as `data.bin`'s change back from junk to data. Your file is still on disk, but its commit is already gone from every branch. + +Meanwhile a collaborator pushes a commit to the sibling, and you `update` as usual: + + +{{< cols >}} +{{% col 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 +caf5fc5 (master) add theirs +9687243 add precious data +544800b add data +3ac59df edit file + +$ # precious.bin is still there, next to theirs.bin +$ ls +data.bin +file.bin +precious.bin +theirs.bin + +$ # data, as after the reset +$ cat data.bin +data +``` +{{% /col %}} +{{% col 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) + +$ # the collaborator's 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 + +$ # and the junk is back: master never dropped it +$ cat data.bin +junk +``` +{{% /col %}} +{{< /cols >}} + + +`precious.bin` is gone, and the junk is back. That's because `update` builds the adjusted branch afresh from `basis`, which has never seen `precious.bin` or the reset on the junk. 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: + + +{{< cols >}} +{{% col 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 2e0aab6 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 +``` +{{% /col %}} +{{% col 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, not the content: no hook ran after the reset +$ cat notes.bin +/annex/objects/MD5E-s8--f75b….bin + +$ # post-checkout runs "git annex smudge --update" +$ git checkout -- . + +$ # the content is back +$ cat notes.bin +content +``` +{{% /col %}} +{{< /cols >}} + + +The content is still in the annex, but the work tree holds the pointer. +`git reset` writes the pointer and fires no hook, so `git annex smudge --update` never runs (see [how git-annex replaces the pointer by its content](#the-clean-and-smudge-filter) above). +`git checkout -- .` fires `post-checkout`, which runs it. +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. + +### 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` + + +{{< cols single="true" >}} +{{% col 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 sits 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 +``` +{{% /col %}} +{{< /cols >}} + + +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` (files hold paths, 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` (pointer files) | +| discard commits | reset `master`, then `git annex adjust --unlock --force`; or `datalad update --how=reset` | `git reset --hard HEAD~N` on `adjusted/master(unlocked)` | +| look at history | `git log master` | read `HEAD` as your last commit | + +## Bonus: Why adjusted-branch bugs slip through, and how to test for them + +Many tests in DataLad's test suite are skipped on Windows. Not because there is no Windows to run them on (there is Windows CI), and not because an adjusted branch cannot be had on Linux (it always can). They are skipped because Windows has no normal branch: a test that silently relies on normal-branch behavior fails there for reasons unrelated to what it tests, and the easy fix is to skip it. The code paths that only run on the adjusted branch end up as the ones without tests. + +**What normal-branch behavior means.** A test relies on it when it assumes that + +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 symlinks: read-only, mode `120000` (see [Lock & unlock](#lock--unlock)). + +**Strategy 1: write tests that do not rely on normal-branch behavior.** Most of the four assumptions 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()`). +- Name commits, do not count them from `HEAD`: `HEAD~1` is your previous commit on a normal branch and only the tip of `master` on the adjusted branch, as the first reset brick 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.py` gets halfway: on a normal branch 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 a normal branch, an adjusted branch and a crippled filesystem, so that every part of it actually runs, on Linux too. The normal branch is the baseline that checks parity with git. The adjusted branch (`git annex adjust --unlock` on a filesystem with symlinks) exercises the branch logic behind assumptions 1 to 3. The crippled filesystem adds the filesystem consequences behind assumption 4, such as path text instead of a symlink on `master`. On Windows only the normal leg is impossible, so only that leg is skipped. + +**Strategy 3: know what can be simulated where.** A crippled filesystem can be simulated on Linux by setting `annex.crippledfilesystem=true` before the dataset is created; git-annex then takes its Windows code path: + + +{{< cols single="true" >}} +{{% col title="Linux" %}} +```console +$ # pretend the filesystem is crippled, before the dataset exists +$ export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=annex.crippledfilesystem GIT_CONFIG_VALUE_0=true +$ cd .. && datalad create sim && cd sim +[INFO] Filesystem does not allow removing write bit from files. +| Detected a crippled filesystem. +[INFO] Disabling core.symlinks. +[INFO] Entering an adjusted branch where files are unlocked as this filesystem does not support locked files. +[INFO] Switched to branch 'adjusted/master(unlocked)' +create(ok): /tmp/…/sim (dataset) + +$ echo "1" > one.bin +$ datalad save -m "add one" +add(ok): one.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ echo "2" > two.bin +$ datalad save -m "add two" +add(ok): two.bin (file) +save(ok): . (dataset) +action summary: + add (ok: 1) + save (ok: 1) + +$ # the correct reset from above ... +$ git checkout master +Switched to branch 'master' + +$ git reset --hard HEAD~1 +git-annex: git status will show one.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 dd79480 add one + +$ # ... fails in the simulation, while it works on Windows +$ git annex adjust --unlock --force +adjust +error: Your local changes to the following files would be overwritten by checkout: + one.bin +Please commit your changes or stash them before you switch branches. +Aborting +failed +adjust: 1 failed +``` +{{% /col %}} +{{< /cols >}} + + +Almost everything in this post reproduces in this simulation: the adjusting commit, `basis`, path text on `master`, the pointer after a reset and the swallowed `save`. +The exception is shown above. Whenever git swaps an annexed file between its symlink form and its unlocked form while the content is present, the simulated repository believes the file is modified, because the matching bookkeeping exists only in git-annex's Windows build, behind a compile-time switch. No setting changes that. Since the switch is decided when git-annex is built, not by the filesystem, a Linux filesystem without symlinks, such as a FAT-formatted drive, should not change it either; we have not tested that. +It shows as a "git-annex restage" warning after `git reset --hard`, as the failing `adjust` above, as a failing switch from `master` back to the adjusted branch, and as a failing `datalad update` after the resets, so the data loss on `update` cannot be replayed in the simulation either. These are the cases to leave to Windows CI. + +| | Linux | Windows | +|---|---|---| +| normal branch | yes | no: skip this leg | +| adjusted branch | yes, with `git annex adjust` | yes | +| crippled filesystem | simulated; swapping file forms with content present: expected failure | yes | + +Skip and expected failure are different tools for the two gaps above: the normal branch that Windows cannot have, and the swap that the simulation cannot reproduce. Skip a test where its case cannot even be set up, which is only the normal leg on Windows: there is nothing to learn. Mark a test as an expected failure (`pytest.mark.xfail(strict=False)`) where the case is meaningful and passes on real Windows but the simulation cannot reproduce it, and attach the mark only under the simulation, for example when the filesystem is crippled yet can still create symlinks. 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 switched to `master` by accident, saved a file there, switched back to the adjusted branch, saved another file, and pushed. The simulation cannot play this one through: on Linux, switching back already fails. Here is what you did on Windows: + + +{{< cols single="true" >}} +{{% col 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 +``` +{{% /col %}} +{{< /cols >}} + + +1. Which of the two files, `saved-on-master.bin` and `saved-on-adjusted.bin`, are in your work tree, on the adjusted branch, on `master`, and on the sibling? + +Then your collaborator adds a file and pushes it, and you `update`: + + +{{< cols single="true" >}} +{{% col 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 +``` +{{% /col %}} +{{< /cols >}} + + +2. Which files are where now? +3. And after a second `datalad push`? + +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: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)). 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..6eb590a --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/story-linux.sh @@ -0,0 +1,119 @@ +#!/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)" + + +# --- 00-locked +# create stays on master +datalad create repo && cd repo +echo "content" > file.bin +datalad save -m "add file" +# a symlink into the annex store, where the content is read-only +ls -l file.bin +# git records a symlink (mode 120000) +git ls-tree HEAD file.bin +# unlock replaces the symlink with a writable copy +datalad unlock file.bin +ls -l file.bin +# the symlink -> file switch is staged as a typechange +git status +echo "new content" > file.bin +datalad save -m "edit file" +# save stores the new content as a new read-only object and puts a new symlink in place +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, so 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, next to theirs.bin +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 +# pretend the filesystem is crippled, before the dataset exists +export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=annex.crippledfilesystem GIT_CONFIG_VALUE_0=true +cd .. && datalad create sim && cd sim +echo "1" > one.bin +datalad save -m "add one" +echo "2" > two.bin +datalad save -m "add two" +# the correct reset from above ... +git checkout master +git reset --hard HEAD~1 +set +e # setup +# ... fails in the simulation, 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..fb38cec --- /dev/null +++ b/content/posts/adjusted-branch-unlocked/story-windows.sh @@ -0,0 +1,160 @@ +#!/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)" + + +# --- 00-locked +# create detects a crippled filesystem and checks out the adjusted branch by itself +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 +# 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" +# still a regular file, now with the new content +ls -l file.bin + +# --- 01-refs +# HEAD is the "git-annex adjusted branch" commit: it turns the symlink into a regular file; your last commit is below it +git log --oneline --decorate --summary -3 +# adjusted branch checked out, master next to it +git branch + +# --- 02-two-shapes +# leave the adjusted branch, switch to master +git switch master +# no symlink to follow, only a regular file that contains the literal path +cat file.bin +# a regular file of 118 bytes (the path), not 12 (the content) +ls -l file.bin +# git records 120000 (symlink), not 100644 (regular file)! +git ls-tree HEAD file.bin +# back to the adjusted branch: the content is there again +git switch "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' +# post-checkout and post-merge 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 adjusting 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 copy of the junk commit, only the adjusting commit is gone +# drop one more? +git reset --hard HEAD~1 +# still not data: the path to data's object, master's symlink form +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 top of master, junk included; "add precious data" is not in master ... +git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master +# ... and "add precious data" is on no branch at all +git log --all --oneline --no-decorate --grep "add precious data" +# precious.bin sits inside the adjusting commit instead, and so does 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 +# the collaborator's 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 +# and 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, not the content: no hook ran after the reset +cat notes.bin +# post-checkout runs "git annex smudge --update" +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 sits 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..f3871d0 --- /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. + -- 2.54.1 From 502f707cf5c9e911e000d3e8e55bb8f004007da7 Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Fri, 6 Nov 2026 18:44:24 +0100 Subject: [PATCH 3/7] rename the shortcodes with a dl prefix cols, col, md and details become dlcols, dlcol, dlmd and dldetails, so that they cannot collide with shortcodes Hugo adds later: Hugo has shipped its own details since v0.140.0, which ours replaced site-wide. --- .../posts/adjusted-branch-unlocked/index.md | 152 +++++++++--------- layouts/shortcodes/{col.html => dlcol.html} | 0 layouts/shortcodes/{cols.html => dlcols.html} | 0 .../{details.html => dldetails.html} | 0 layouts/shortcodes/{md.html => dlmd.html} | 0 5 files changed, 76 insertions(+), 76 deletions(-) rename layouts/shortcodes/{col.html => dlcol.html} (100%) rename layouts/shortcodes/{cols.html => dlcols.html} (100%) rename layouts/shortcodes/{details.html => dldetails.html} (100%) rename layouts/shortcodes/{md.html => dlmd.html} (100%) diff --git a/content/posts/adjusted-branch-unlocked/index.md b/content/posts/adjusted-branch-unlocked/index.md index 8c0a630..16c27d5 100644 --- a/content/posts/adjusted-branch-unlocked/index.md +++ b/content/posts/adjusted-branch-unlocked/index.md @@ -39,8 +39,8 @@ Instead, git-annex keeps two copies of each annexed file: one in `.git/annex/obj Upon `datalad create`, git-annex automatically checks out an adjusted branch, `adjusted/master(unlocked)`. This is where the second copy lives. It is called **unlocked**[^fn:modes] because every annexed file in it is unlocked. So each annexed file is either dropped or on disk twice. -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ # create stays on master $ datalad create repo && cd repo @@ -91,8 +91,8 @@ $ # save stores the new content as a new read-only object and puts a new symlink $ ls -l file.bin lrwxrwxrwx 118 file.bin -> .git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ # create detects a crippled filesystem and checks out the adjusted branch by itself $ datalad create repo && cd repo @@ -145,8 +145,8 @@ $ # still a regular file, now with the new content $ ls -l file.bin -rw-r--r-- 12 file.bin ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} ## master & adjusted/master(unlocked) @@ -156,8 +156,8 @@ Does that mean the history is managed differently on the adjusted branch? Not re The adjusted branch, `adjusted/master(unlocked)`, is a branch like any other. It points to one specific commit, "git-annex adjusted branch", whose parent is the tip of `master`, so its history is exactly `master`'s plus that one commit. git-annex made that commit, not you, and its only change is what `--summary` reports: `mode change 120000 => 100644` for every annexed file in the tree. `master` is called the adjusted branch's **corresponding branch**. -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ # HEAD is your last commit $ git log --oneline --decorate --summary -2 @@ -170,8 +170,8 @@ $ git branch git-annex * master ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ # HEAD is the "git-annex adjusted branch" commit: it turns the symlink into a regular file; your last commit is below it $ git log --oneline --decorate --summary -3 @@ -187,22 +187,22 @@ $ git branch git-annex master ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} Why is the adjusted branch necessary? Let's understand how `master` behaves on a crippled filesystem. -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ # already on master, the symlink is followed $ cat file.bin new content ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ # leave the adjusted branch, switch to master $ git switch master @@ -227,8 +227,8 @@ Switched to branch 'adjusted/master(unlocked)' $ cat file.bin new content ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} Notice that git still records the mode `120000` (symlink) on `master` on Windows, but we just said that symlinks don't work here. On `master` with `core.symlinks=false` (set by git-annex), git cannot create the symlink, so it writes a regular file whose content is the link target path. It is not a broken symlink, it is not a symlink at all. This is why you cannot work on `master` on Windows: annexed files there contain a path, not your data. git keeps recording mode `120000` deliberately, so the history stays exactly as on Linux. To decide whether such a file was modified, git compares its content, the path text, with the recorded link target. @@ -241,14 +241,14 @@ Notice that git still records the mode `120000` (symlink) on `master` on Windows | read by | the operating system | git-annex, whose hooks put the content on disk | | work tree gets | a symlink to the content; on Windows, a text file holding the path | a regular file with the content | -{{< details summary="Under the hood: how does git-annex replace the pointer by its content?" id="the-clean-and-smudge-filter" >}} -{{% md %}} +{{< dldetails summary="Under the hood: how does git-annex replace the pointer by its content?" 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. -{{% /md %}} +{{% /dlmd %}} -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ # the filter is set up here too ... $ git check-attr filter -- file.bin @@ -277,8 +277,8 @@ $ git cat-file -p :file.bin $ cat file.bin new content ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ # every path goes through the annex filter $ git check-attr filter -- file.bin @@ -308,11 +308,11 @@ $ git cat-file -p :file.bin $ cat file.bin new content ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} -{{% md %}} +{{% 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.) @@ -326,8 +326,8 @@ 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 a normal branch files are locked and git stores symlinks, so the filter has nothing to do. -{{% /md %}} -{{< /details >}} +{{% /dlmd %}} +{{< /dldetails >}} ## How your work reaches `master` @@ -350,8 +350,8 @@ A plain `git commit` works too, but with two caveats: it lands on the adjusted b git-annex only replays commits that come after an adjusting commit; that becomes important when you reset. -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ # only master: your commits $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ @@ -359,8 +359,8 @@ $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/ 26ca99a add file f949e5b [DATALAD] new dataset ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ # master and basis on your last commit, the adjusted branch one adjusting commit above $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ @@ -370,8 +370,8 @@ $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/ 07b40fc [DATALAD] new dataset 0cf32cf commit before entering adjusted branch ``` -{{% /col %}} -{{< /cols >}} +{{% /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: @@ -396,8 +396,8 @@ On a normal branch, going back is a single `git reset`. On the adjusted branch, Say you save some data, then accidentally overwrite it with junk, and you want the junk commit gone: -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ echo "data" > data.bin $ datalad save -m "add data" @@ -437,8 +437,8 @@ $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/ 26ca99a add file f949e5b [DATALAD] new dataset ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ echo "data" > data.bin $ datalad save -m "add data" @@ -477,8 +477,8 @@ cf4c030 (adjusted/master(unlocked)) add data 95790da edit file 500fb52 add file ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} The first reset removed git-annex's adjusting commit, and with it the unlocked copies in your work tree. @@ -488,8 +488,8 @@ Meanwhile neither `basis` nor `master` has moved: both still point at the junk c So you give up on getting the content back to the work tree and keep working: -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ # data is back, keep working $ echo "precious" > precious.bin @@ -515,8 +515,8 @@ data.bin file.bin precious.bin ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ # keep working $ echo "precious" > precious.bin @@ -550,8 +550,8 @@ data.bin file.bin precious.bin ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} `datalad save` reports `ok`, but "add precious data" is nowhere. @@ -560,8 +560,8 @@ git-annex only carries over commits made on top of an adjusting commit; the firs Meanwhile a collaborator pushes a commit to the sibling, and you `update` as usual: -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ datalad update --how=merge -s sibling [INFO] Fetching updates for Dataset(/tmp/…/repo) @@ -593,8 +593,8 @@ $ # data, as after the reset $ cat data.bin data ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ datalad update --how=merge -s sibling [INFO] Fetching updates for Dataset("C:\…\repo") @@ -624,8 +624,8 @@ $ # and the junk is back: master never dropped it $ cat data.bin junk ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} `precious.bin` is gone, and the junk is back. That's because `update` builds the adjusted branch afresh from `basis`, which has never seen `precious.bin` or the reset on the junk. And that's why the adjusted branch is considered _disposable_. @@ -635,8 +635,8 @@ The rule: **never move the adjusted branch backwards.** Even discarding an *unsaved* edit has a catch: -{{< cols >}} -{{% col title="Linux" %}} +{{< dlcols >}} +{{% dlcol title="Linux" %}} ```console $ echo "content" > notes.bin $ datalad save -m "add notes" @@ -668,8 +668,8 @@ $ git checkout -- . $ cat notes.bin content ``` -{{% /col %}} -{{% col title="Windows" %}} +{{% /dlcol %}} +{{% dlcol title="Windows" %}} ```console $ echo "content" > notes.bin $ datalad save -m "add notes" @@ -699,8 +699,8 @@ $ # the content is back $ cat notes.bin content ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} The content is still in the annex, but the work tree holds the pointer. @@ -718,8 +718,8 @@ If you have followed the tale of the adjusted branch so far, you probably alread 3. rebuild the adjusted branch: `git annex adjust --unlock --force` -{{< cols single="true" >}} -{{% col title="Windows" %}} +{{< dlcols single="true" >}} +{{% dlcol title="Windows" %}} ```console $ # leave the adjusted branch $ git checkout master @@ -755,8 +755,8 @@ $ # but junk is gone! $ cat data.bin data ``` -{{% /col %}} -{{< /cols >}} +{{% /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. @@ -796,8 +796,8 @@ Many tests in DataLad's test suite are skipped on Windows. Not because there is **Strategy 3: know what can be simulated where.** A crippled filesystem can be simulated on Linux by setting `annex.crippledfilesystem=true` before the dataset is created; git-annex then takes its Windows code path: -{{< cols single="true" >}} -{{% col title="Linux" %}} +{{< dlcols single="true" >}} +{{% dlcol title="Linux" %}} ```console $ # pretend the filesystem is crippled, before the dataset exists $ export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=annex.crippledfilesystem GIT_CONFIG_VALUE_0=true @@ -843,8 +843,8 @@ Aborting failed adjust: 1 failed ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} Almost everything in this post reproduces in this simulation: the adjusting commit, `basis`, path text on `master`, the pointer after a reset and the swallowed `save`. @@ -864,8 +864,8 @@ Skip and expected failure are different tools for the two gaps above: the normal Say you switched to `master` by accident, saved a file there, switched back to the adjusted branch, saved another file, and pushed. The simulation cannot play this one through: on Linux, switching back already fails. Here is what you did on Windows: -{{< cols single="true" >}} -{{% col title="Windows" %}} +{{< dlcols single="true" >}} +{{% dlcol title="Windows" %}} ```console $ cd .. && datalad create puzzle && cd puzzle $ git init -q --bare ../puzzle-sibling.git @@ -884,8 +884,8 @@ $ echo "second" > saved-on-adjusted.bin $ datalad save -m "save on the adjusted branch" $ datalad push --to sibling ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} 1. Which of the two files, `saved-on-master.bin` and `saved-on-adjusted.bin`, are in your work tree, on the adjusted branch, on `master`, and on the sibling? @@ -893,8 +893,8 @@ $ datalad push --to sibling Then your collaborator adds a file and pushes it, and you `update`: -{{< cols single="true" >}} -{{% col title="Windows" %}} +{{< dlcols single="true" >}} +{{% dlcol title="Windows" %}} ```console $ # your collaborator adds a file and pushes it $ datalad -C ../collaborator update --how=merge @@ -905,8 +905,8 @@ $ datalad -C ../collaborator push --to origin $ # you update $ datalad update --how=merge -s sibling ``` -{{% /col %}} -{{< /cols >}} +{{% /dlcol %}} +{{< /dlcols >}} 2. Which files are where now? diff --git a/layouts/shortcodes/col.html b/layouts/shortcodes/dlcol.html similarity index 100% rename from layouts/shortcodes/col.html rename to layouts/shortcodes/dlcol.html diff --git a/layouts/shortcodes/cols.html b/layouts/shortcodes/dlcols.html similarity index 100% rename from layouts/shortcodes/cols.html rename to layouts/shortcodes/dlcols.html diff --git a/layouts/shortcodes/details.html b/layouts/shortcodes/dldetails.html similarity index 100% rename from layouts/shortcodes/details.html rename to layouts/shortcodes/dldetails.html diff --git a/layouts/shortcodes/md.html b/layouts/shortcodes/dlmd.html similarity index 100% rename from layouts/shortcodes/md.html rename to layouts/shortcodes/dlmd.html -- 2.54.1 From 916514954687930a9d87a858b1a86e5cad812203 Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Fri, 6 Nov 2026 18:44:30 +0100 Subject: [PATCH 4/7] dlcols: accept single=true unquoted, move the CSS to a stylesheet dlcols only matched the string "true", so single=true without quotes built fine but gave two columns. Its style block was repeated with every use; in assets/css/extended/ PaperMod bundles it into the site stylesheet once. dlmd and dldetails get a comment on why dlmd is needed and why dldetails is not Hugo's built-in details, which drops the id that a link points to. --- assets/css/extended/dlcols.css | 7 +++++++ layouts/shortcodes/dlcols.html | 10 +--------- layouts/shortcodes/dldetails.html | 3 +++ layouts/shortcodes/dlmd.html | 5 +++++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 assets/css/extended/dlcols.css 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/layouts/shortcodes/dlcols.html b/layouts/shortcodes/dlcols.html index 5d552b2..a0f7c3e 100644 --- a/layouts/shortcodes/dlcols.html +++ b/layouts/shortcodes/dlcols.html @@ -1,11 +1,3 @@ -
+
{{ .Inner }}
- diff --git a/layouts/shortcodes/dldetails.html b/layouts/shortcodes/dldetails.html index 70311d7..3a0cb99 100644 --- a/layouts/shortcodes/dldetails.html +++ b/layouts/shortcodes/dldetails.html @@ -1,3 +1,6 @@ +{{- /* 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 index 59448a1..bbb27c1 100644 --- a/layouts/shortcodes/dlmd.html +++ b/layouts/shortcodes/dlmd.html @@ -1 +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 }} -- 2.54.1 From 70d3325e8afe81847ca283873f4d25596a9e5124 Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Tue, 17 Nov 2026 19:04:16 +0100 Subject: [PATCH 5/7] post: keep the "dashed" label inside sync-update.svg The label ran about 3px past the right edge of the 720px frame. --- content/posts/adjusted-branch-unlocked/sync-update.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/posts/adjusted-branch-unlocked/sync-update.svg b/content/posts/adjusted-branch-unlocked/sync-update.svg index f3871d0..1287383 100644 --- a/content/posts/adjusted-branch-unlocked/sync-update.svg +++ b/content/posts/adjusted-branch-unlocked/sync-update.svg @@ -84,7 +84,7 @@ adjusted/master(unlocked) basis master - dashed: only if master moved on its own + dashed: only if master moved on its own -- 2.54.1 From 253666abf82e39c4da61d87575cdb29d38acbca3 Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Tue, 17 Nov 2026 19:04:16 +0100 Subject: [PATCH 6/7] post: revise after review The post now builds on one distinction: reading should cost nothing, writing must leave the stored version intact. A locked file serves both through a symlink; on Windows git-annex does not use symlinks, so master holds path-text files there, and the adjusted branch provides an unlocked copy of every annexed file instead. git's records (a symlink with the path, or a regular file with a pointer) are named as such and kept apart from what lands in the work tree. Corrections from review: - The simulation's false "modified" is no compile-time switch. core.symlinks=false alone reproduces it, so the no-symlink test leg sets just that. On Linux git-annex's filter fills master's path-text files with their content; on Windows the same replacement fails because git holds the file open, and git-annex ignores the error. - core.symlinks=false is simply the setting on Windows; who sets it is not the point. - A plain git commit reaches master at the next update, push, or save that commits something. - get_corresponding_branch() is paired with get_active_branch(). - test_unlock is named as the test that skips its checks. - When git status puts the content back after a plain reset is a matter of timing on Linux and never happens on Windows; that detail moved to a footnote, and the main text gives git checkout -- . as the reliable way. Also: shortcodes renamed in the post, "normal branch" and "crippled" replaced by what is meant, the testing section opens with the properties tests rely on, and strategy 3 is about reproducing Windows on Linux. Examples: a cat in the first example shows that a locked file is readable, git checkout replaces git switch, example 14 names its files kept.bin and discarded.bin after their role, and column comments are shorter. The downloadable scripts start new repositories on master whatever init.defaultBranch says. --- .../posts/adjusted-branch-unlocked/index.md | 302 ++++++++++-------- .../adjusted-branch-unlocked/story-linux.sh | 34 +- .../adjusted-branch-unlocked/story-windows.sh | 67 ++-- 3 files changed, 224 insertions(+), 179 deletions(-) diff --git a/content/posts/adjusted-branch-unlocked/index.md b/content/posts/adjusted-branch-unlocked/index.md index 16c27d5..5b1e6b3 100644 --- a/content/posts/adjusted-branch-unlocked/index.md +++ b/content/posts/adjusted-branch-unlocked/index.md @@ -21,22 +21,21 @@ disableShare: false hideSummary: false --- -On Windows, every DataLad dataset lives on an **adjusted branch**. -It is a handful of git refs, a git filter, and one rule about which branch is the real one. -Once you know these, its surprises make sense. +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. -The examples below are one continuous story, cut into small pieces, each shown with its output side by side: a normal branch 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. +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 & unlock +## Lock and unlock -A **locked** file is a read-only file that holds the content and sits in the annex store `.git/annex/objects/`, named by its **key** (git-annex's name for the object, e.g. `MD5E-s8--f75b….bin`: the size in bytes, `s8`, plus the **checksum**, a fingerprint of the content). The work tree only holds a **symlink** (a tiny file that just points to another path). Writing to it fails with `Permission denied`. `datalad unlock` replaces the symlink with a writable copy in the work tree. `datalad save` stores the edit as a new read-only object in the annex store and replaces the file in the work tree with the new symlink. The old object simply stays in the annex store and can be retrieved by checking out the associated commit. +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: -On Windows there is no such thing as a locked file, because symlinks don't work there (thus crippled filesystem). -A Windows user only ever sees normal, writable files in a DataLad dataset. -Instead, git-annex keeps two copies of each annexed file: one in `.git/annex/objects/`, and a writable one in the work tree. -Upon `datalad create`, git-annex automatically checks out an adjusted branch, `adjusted/master(unlocked)`. This is where the second copy lives. It is called **unlocked**[^fn:modes] because every annexed file in it is unlocked. So each annexed file is either dropped or on disk twice. +- 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 >}} @@ -54,7 +53,7 @@ action summary: add (ok: 1) save (ok: 1) -$ # a symlink into the annex store, where the content is read-only +$ # 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 @@ -62,7 +61,11 @@ $ # git records a symlink (mode 120000) $ git ls-tree HEAD file.bin 120000 blob af2b030… file.bin -$ # unlock replaces the symlink with a writable copy +$ # 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 @@ -72,7 +75,7 @@ unlock(ok): file.bin (file) $ ls -l file.bin -rw-r--r-- 8 file.bin -$ # the symlink -> file switch is staged as a typechange +$ # staged as a typechange $ git status On branch master Changes to be committed: @@ -87,14 +90,14 @@ action summary: add (ok: 1) save (ok: 1) -$ # save stores the new content as a new read-only object and puts a new symlink in place +$ # 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 detects a crippled filesystem and checks out the adjusted branch by itself +$ # create checks out the adjusted branch $ datalad create repo && cd repo [INFO] Detected a filesystem without fifo support. [INFO] Disabling ssh connection caching. @@ -120,6 +123,10 @@ $ # 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 @@ -141,7 +148,7 @@ action summary: add (ok: 1) save (ok: 1) -$ # still a regular file, now with the new content +$ # a regular file with the new content $ ls -l file.bin -rw-r--r-- 12 file.bin ``` @@ -151,9 +158,9 @@ $ ls -l file.bin ## master & adjusted/master(unlocked) -Does that mean the history is managed differently on the adjusted branch? 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. +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 specific commit, "git-annex adjusted branch", whose parent is the tip of `master`, so its history is exactly `master`'s plus that one commit. git-annex made that commit, not you, and its only change is what `--summary` reports: `mode change 120000 => 100644` for every annexed file in the tree. `master` is called the adjusted branch's **corresponding branch**. +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 >}} @@ -161,8 +168,8 @@ The adjusted branch, `adjusted/master(unlocked)`, is a branch like any other. It ```console $ # HEAD is your last commit $ git log --oneline --decorate --summary -2 -3ac59df (HEAD -> master) edit file -26ca99a add file +6e02b1a (HEAD -> master) edit file +d7f438d add file create mode 120000 file.bin $ # only master @@ -173,7 +180,9 @@ $ git branch {{% /dlcol %}} {{% dlcol title="Windows" %}} ```console -$ # HEAD is the "git-annex adjusted branch" commit: it turns the symlink into a regular file; your last commit is below it +$ # 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 @@ -181,7 +190,7 @@ $ git log --oneline --decorate --summary -3 500fb52 add file create mode 120000 file.bin -$ # adjusted branch checked out, master next to it +$ # on the adjusted branch, master next to it $ git branch * adjusted/master(unlocked) git-annex @@ -191,7 +200,7 @@ $ git branch {{< /dlcols >}} -Why is the adjusted branch necessary? Let's understand how `master` behaves on a crippled filesystem. +`master` can still be checked out on Windows, but its annexed files are path-text files: {{< dlcols >}} @@ -204,24 +213,24 @@ new content {{% /dlcol %}} {{% dlcol title="Windows" %}} ```console -$ # leave the adjusted branch, switch to master -$ git switch master +$ # check out master +$ git checkout master Switched to branch 'master' -$ # no symlink to follow, only a regular file that contains the literal path +$ # a path-text file $ cat file.bin .git/annex/objects/w2/Vg/MD5E-s12--f8a6….bin/MD5E-s12--f8a6….bin -$ # a regular file of 118 bytes (the path), not 12 (the content) +$ # 118 bytes (the path), not 12 (content) $ ls -l file.bin -rw-r--r-- 118 file.bin -$ # git records 120000 (symlink), not 100644 (regular file)! +$ # git records 120000 (symlink)! $ git ls-tree HEAD file.bin 120000 blob 4488793… file.bin -$ # back to the adjusted branch: the content is there again -$ git switch "adjusted/master(unlocked)" +$ # back on the adjusted branch: content +$ git checkout "adjusted/master(unlocked)" Switched to branch 'adjusted/master(unlocked)' $ cat file.bin @@ -231,17 +240,14 @@ new content {{< /dlcols >}} -Notice that git still records the mode `120000` (symlink) on `master` on Windows, but we just said that symlinks don't work here. On `master` with `core.symlinks=false` (set by git-annex), git cannot create the symlink, so it writes a regular file whose content is the link target path. It is not a broken symlink, it is not a symlink at all. This is why you cannot work on `master` on Windows: annexed files there contain a path, not your data. git keeps recording mode `120000` deliberately, so the history stays exactly as on Linux. To decide whether such a file was modified, git compares its content, the path text, with the recorded link target. +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. -| | `master` | `adjusted/master(unlocked)` | +| on Windows | `master` | `adjusted/master(unlocked)` | |---|---|---| -| annexed files are | locked | unlocked | -| git mode | `120000` (symlink) | `100644` (regular file) | -| git stores | a **symlink target** (the object's path): `.git/annex/objects/…//` | a **pointer** (a small text that names the object by its key): `/annex/objects/` | -| read by | the operating system | git-annex, whose hooks put the content on disk | -| work tree gets | a symlink to the content; on Windows, a text file holding the path | a regular file with the content | +| 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 replace the pointer by its content?" id="the-clean-and-smudge-filter" >}} +{{< 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 %}} @@ -270,7 +276,8 @@ post-receive pre-commit pre-push -$ # ... but git stores a symlink, so the filter has nothing to do +$ # ... 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 @@ -293,7 +300,7 @@ filter.annex.smudge git-annex smudge -- %f filter.annex.clean git-annex smudge --clean -- %f filter.annex.process git-annex filter-process -$ # post-checkout and post-merge run "git annex smudge --update" +$ # hooks run "git annex smudge --update" $ ls .git/hooks | grep -v sample post-checkout post-merge @@ -301,7 +308,8 @@ post-receive pre-commit pre-push -$ # git stores a pointer, git-annex put the content on disk +$ # git stores a pointer, +$ # git-annex put the content on disk $ git cat-file -p :file.bin /annex/objects/MD5E-s12--f8a6….bin @@ -325,29 +333,27 @@ Three pieces make this work, and `git annex init` writes all three: 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 a normal branch files are locked and git stores symlinks, so the filter has nothing to do. +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` -You work on the adjusted branch, but only what reaches `master` counts; anything else can be lost. So how does your work get there? +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? -git-annex uses a third **ref** (a named reference to a commit, such as HEAD; a branch is one kind of ref) `refs/basis/adjusted/master(unlocked)`, to sync between the corresponding branch and the adjusted branch; for `datalad save` this is a purely local `git annex sync` (`--no-push --no-pull`). -`basis` records which `master` commit the adjusted branch was built from. -git-annex keeps this record separately because `master` itself can change under its feet, for example when someone pushes into your repository. -When you `datalad save` on the adjusted branch, this happens in order: +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 to the object, as on Linux. +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 that carried something over, `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 with two caveats: it lands on the adjusted branch, on top of the adjusting commit, and reaches `master` only at the next sync (`save`, `update` or `push`); and on a normal branch it records a file you unlocked as unlocked (mode `100644`), while `datalad save` would have locked it again. So stick to `datalad save`. -git-annex only replays commits that come after an adjusting commit; that becomes important when you reset. +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 >}} @@ -355,14 +361,15 @@ git-annex only replays commits that come after an adjusting commit; that becomes ```console $ # only master: your commits $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -3ac59df (master) edit file -26ca99a add file -f949e5b [DATALAD] new dataset +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 adjusting commit above +$ # 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 @@ -374,22 +381,24 @@ $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/ {{< /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: +`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`, converting every symlink into an unlocked file. +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, personally, being able to go back and rewrite history is the whole point of version control. +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 a normal branch, going back is a single `git reset`. On the adjusted branch, it is where things truly break and what led me to writing this guide. +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? @@ -424,7 +433,7 @@ action summary: $ # drop the junk commit $ git reset --hard HEAD~1 -HEAD is now at 544800b add data +HEAD is now at 43d524e add data $ # data again $ cat data.bin @@ -432,10 +441,10 @@ data $ # the junk commit is gone $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master -544800b (master) add data -3ac59df edit file -26ca99a add file -f949e5b [DATALAD] new dataset +43d524e (master) add data +6e02b1a edit file +d7f438d add file +99622d4 [DATALAD] new dataset ``` {{% /dlcol %}} {{% dlcol title="Windows" %}} @@ -461,16 +470,18 @@ $ # 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 copy of the junk commit, only the adjusting commit is gone +$ # 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: the path to data's object, master's symlink form +$ # 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 +$ # 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 @@ -481,9 +492,9 @@ cf4c030 (adjusted/master(unlocked)) add data {{< /dlcols >}} -The first reset removed git-annex's adjusting commit, and with it the unlocked copies in your work tree. -Every commit below it is a `master` commit, which records files as symlinks, so no matter how far back you reset, `data.bin` only ever holds the symlink's target path (the content itself is still safe in the annex store). -Meanwhile neither `basis` nor `master` has moved: both still point at the junk commit. And you are still on `adjusted/master(unlocked)`. +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: @@ -502,13 +513,13 @@ action summary: $ # "add precious data" on top of "add data" $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master -9687243 (master) add precious data -544800b add data -3ac59df edit file -26ca99a add file +b868b97 (master) add precious data +43d524e add data +6e02b1a edit file +d7f438d add file $ git log --all --oneline --no-decorate --grep "add precious data" -9687243 add precious data +b868b97 add precious data $ ls data.bin @@ -527,17 +538,19 @@ action summary: add (ok: 1) save (ok: 1) -$ # a new adjusting commit on top of master, junk included; "add precious data" is not in master ... +$ # 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 -$ # ... and "add precious data" is on no branch at all +$ # ... nor on any branch $ git log --all --oneline --no-decorate --grep "add precious data" -$ # precious.bin sits inside the adjusting commit instead, and so does data.bin's way back to 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 +- @@ -554,8 +567,8 @@ precious.bin {{< /dlcols >}} -`datalad save` reports `ok`, but "add precious data" is nowhere. -git-annex only carries over commits made on top of an adjusting commit; the first reset removed it, so your new commit is skipped. git-annex still puts a new adjusting commit on top of `basis`, which holds the should-be-discarded junk commit but not the should-be-committed precious commit. That new adjusting commit takes the tree of your last commit as it is, so by mistake it includes `precious.bin`, as well as `data.bin`'s change back from junk to data. Your file is still on disk, but its commit is already gone from every branch. +`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: @@ -577,12 +590,12 @@ action summary: update.annex_merge (ok: 1) $ git log --oneline --decorate --decorate-refs=refs/heads/ --decorate-refs=refs/basis/ -4 HEAD master -caf5fc5 (master) add theirs -9687243 add precious data -544800b add data -3ac59df edit file +d7f2b7f (master) add theirs +b868b97 add precious data +43d524e add data +6e02b1a edit file -$ # precious.bin is still there, next to theirs.bin +$ # precious.bin is still there $ ls data.bin file.bin @@ -607,20 +620,23 @@ action summary: update (ok: 1) update.annex_sync (ok: 1) -$ # the collaborator's commit on top of the junk, a new adjusting commit on top; no precious data anywhere +$ # 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 +$ # precious.bin is gone: the adjusted +$ # branch was rebuilt from basis $ ls data.bin file.bin theirs.bin -$ # and the junk is back: master never dropped it +$ # the junk is back: master never dropped it $ cat data.bin junk ``` @@ -628,7 +644,7 @@ junk {{< /dlcols >}} -`precious.bin` is gone, and the junk is back. That's because `update` builds the adjusted branch afresh from `basis`, which has never seen `precious.bin` or the reset on the junk. And that's why the adjusted branch is considered _disposable_. +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.** @@ -654,7 +670,7 @@ unlock(ok): notes.bin (file) $ echo "edited" > notes.bin $ git reset --hard -HEAD is now at 2e0aab6 add notes +HEAD is now at fbded2e add notes $ git status On branch master @@ -688,11 +704,12 @@ $ git status On branch adjusted/master(unlocked) nothing to commit, working tree clean -$ # ... but the file holds the pointer, not the content: no hook ran after the reset +$ # ... but the file holds the pointer: +$ # no hook ran after the reset $ cat notes.bin /annex/objects/MD5E-s8--f75b….bin -$ # post-checkout runs "git annex smudge --update" +$ # the post-checkout hook fills it in $ git checkout -- . $ # the content is back @@ -704,10 +721,9 @@ content The content is still in the annex, but the work tree holds the pointer. -`git reset` writes the pointer and fires no hook, so `git annex smudge --update` never runs (see [how git-annex replaces the pointer by its content](#the-clean-and-smudge-filter) above). -`git checkout -- .` fires `post-checkout`, which runs it. -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. +`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 @@ -740,7 +756,7 @@ $ git branch git-annex master -$ # master and basis are reset, the adjusted branch sits on top of them +$ # 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 @@ -765,79 +781,79 @@ DataLad does these steps in `datalad update --how=reset`, to reset to the siblin | | do | don't | |---|---|---| -| edit files | on `adjusted/master(unlocked)` | on `master` (files hold paths, not data) | +| 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` (pointer files) | +| 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)` | -| look at history | `git log master` | read `HEAD` as your last commit | -## Bonus: Why adjusted-branch bugs slip through, and how to test for them +## 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. Not because there is no Windows to run them on (there is Windows CI), and not because an adjusted branch cannot be had on Linux (it always can). They are skipped because Windows has no normal branch: a test that silently relies on normal-branch behavior fails there for reasons unrelated to what it tests, and the easy fix is to skip it. The code paths that only run on the adjusted branch end up as the ones without tests. - -**What normal-branch behavior means.** A test relies on it when it assumes that +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 symlinks: read-only, mode `120000` (see [Lock & unlock](#lock--unlock)). +4. annexed files are locked: read-only, behind a symlink (see [Lock and unlock](#lock-and-unlock)). -**Strategy 1: write tests that do not rely on normal-branch behavior.** Most of the four assumptions can be avoided in the test itself, and then the same test holds on every branch: +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. -- 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()`). -- Name commits, do not count them from `HEAD`: `HEAD~1` is your previous commit on a normal branch and only the tip of `master` on the adjusted branch, as the first reset brick shows. Use the commit's hash, or count from `master`. +**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.py` gets halfway: on a normal branch 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. +- 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 a normal branch, an adjusted branch and a crippled filesystem, so that every part of it actually runs, on Linux too. The normal branch is the baseline that checks parity with git. The adjusted branch (`git annex adjust --unlock` on a filesystem with symlinks) exercises the branch logic behind assumptions 1 to 3. The crippled filesystem adds the filesystem consequences behind assumption 4, such as path text instead of a symlink on `master`. On Windows only the normal leg is impossible, so only that leg is skipped. +**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: know what can be simulated where.** A crippled filesystem can be simulated on Linux by setting `annex.crippledfilesystem=true` before the dataset is created; git-annex then takes its Windows code path: +**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 -$ # pretend the filesystem is crippled, before the dataset exists -$ export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=annex.crippledfilesystem GIT_CONFIG_VALUE_0=true +$ # an adjusted branch with path text on master, as on Windows $ cd .. && datalad create sim && cd sim -[INFO] Filesystem does not allow removing write bit from files. -| Detected a crippled filesystem. -[INFO] Disabling core.symlinks. -[INFO] Entering an adjusted branch where files are unlocked as this filesystem does not support locked files. -[INFO] Switched to branch 'adjusted/master(unlocked)' create(ok): /tmp/…/sim (dataset) -$ echo "1" > one.bin -$ datalad save -m "add one" -add(ok): one.bin (file) +$ 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 "2" > two.bin -$ datalad save -m "add two" -add(ok): two.bin (file) +$ 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 ... +$ # 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 one.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 dd79480 add one +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 in the simulation, while it works on Windows +$ # ... 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: - one.bin + kept.bin Please commit your changes or stash them before you switch branches. Aborting failed @@ -847,21 +863,27 @@ adjust: 1 failed {{< /dlcols >}} -Almost everything in this post reproduces in this simulation: the adjusting commit, `basis`, path text on `master`, the pointer after a reset and the swallowed `save`. -The exception is shown above. Whenever git swaps an annexed file between its symlink form and its unlocked form while the content is present, the simulated repository believes the file is modified, because the matching bookkeeping exists only in git-annex's Windows build, behind a compile-time switch. No setting changes that. Since the switch is decided when git-annex is built, not by the filesystem, a Linux filesystem without symlinks, such as a FAT-formatted drive, should not change it either; we have not tested that. -It shows as a "git-annex restage" warning after `git reset --hard`, as the failing `adjust` above, as a failing switch from `master` back to the adjusted branch, and as a failing `datalad update` after the resets, so the data loss on `update` cannot be replayed in the simulation either. These are the cases to leave to Windows CI. +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 | |---|---|---| -| normal branch | yes | no: skip this leg | -| adjusted branch | yes, with `git annex adjust` | yes | -| crippled filesystem | simulated; swapping file forms with content present: expected failure | yes | +| 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 | -Skip and expected failure are different tools for the two gaps above: the normal branch that Windows cannot have, and the swap that the simulation cannot reproduce. Skip a test where its case cannot even be set up, which is only the normal leg on Windows: there is nothing to learn. Mark a test as an expected failure (`pytest.mark.xfail(strict=False)`) where the case is meaningful and passes on real Windows but the simulation cannot reproduce it, and attach the mark only under the simulation, for example when the filesystem is crippled yet can still create symlinks. 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. +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 switched to `master` by accident, saved a file there, switched back to the adjusted branch, saved another file, and pushed. The simulation cannot play this one through: on Linux, switching back already fails. Here is what you did on Windows: +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" >}} @@ -914,5 +936,7 @@ $ datalad update --how=merge -s sibling 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 index 6eb590a..0e42eae 100644 --- a/content/posts/adjusted-branch-unlocked/story-linux.sh +++ b/content/posts/adjusted-branch-unlocked/story-linux.sh @@ -5,6 +5,7 @@ # 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 @@ -12,18 +13,20 @@ cd "$(mktemp -d)" datalad create repo && cd repo echo "content" > file.bin datalad save -m "add file" -# a symlink into the annex store, where the content is read-only +# a symlink to the read-only content ls -l file.bin # git records a symlink (mode 120000) git ls-tree HEAD file.bin -# unlock replaces the symlink with a writable copy +# reading follows the symlink to the content +cat file.bin +# unlock: symlink -> writable copy datalad unlock file.bin ls -l file.bin -# the symlink -> file switch is staged as a typechange +# staged as a typechange git status echo "new content" > file.bin datalad save -m "edit file" -# save stores the new content as a new read-only object and puts a new symlink in place +# save: new read-only object, new symlink ls -l file.bin # --- 01-refs @@ -42,7 +45,8 @@ 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, so the filter has nothing to do +# ... but git stores a symlink: +# the filter has nothing to do git cat-file -p :file.bin cat file.bin @@ -82,7 +86,7 @@ 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, next to theirs.bin +# precious.bin is still there ls # data, as after the reset cat data.bin @@ -103,17 +107,19 @@ cat notes.bin # --- 14-simulate -# pretend the filesystem is crippled, before the dataset exists -export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=annex.crippledfilesystem GIT_CONFIG_VALUE_0=true +# an adjusted branch with path text on master, as on Windows cd .. && datalad create sim && cd sim -echo "1" > one.bin -datalad save -m "add one" -echo "2" > two.bin -datalad save -m "add two" -# the correct reset from above ... +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 in the simulation, while it works on Windows +# ... 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 index fb38cec..d19b196 100644 --- a/content/posts/adjusted-branch-unlocked/story-windows.sh +++ b/content/posts/adjusted-branch-unlocked/story-windows.sh @@ -5,10 +5,11 @@ # 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 detects a crippled filesystem and checks out the adjusted branch by itself +# create checks out the adjusted branch datalad create repo && cd repo echo "content" > file.bin datalad save -m "add file" @@ -16,6 +17,8 @@ datalad save -m "add file" 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 @@ -23,26 +26,28 @@ ls -l file.bin git status echo "new content" > file.bin datalad save -m "edit file" -# still a regular file, now with the new content +# a regular file with the new content ls -l file.bin # --- 01-refs -# HEAD is the "git-annex adjusted branch" commit: it turns the symlink into a regular file; your last commit is below it +# HEAD is the adjusting commit: +# it turns the symlink into a file; +# your last commit is below it git log --oneline --decorate --summary -3 -# adjusted branch checked out, master next to it +# on the adjusted branch, master next to it git branch # --- 02-two-shapes -# leave the adjusted branch, switch to master -git switch master -# no symlink to follow, only a regular file that contains the literal path +# check out master +git checkout master +# a path-text file cat file.bin -# a regular file of 118 bytes (the path), not 12 (the content) +# 118 bytes (the path), not 12 (content) ls -l file.bin -# git records 120000 (symlink), not 100644 (regular file)! +# git records 120000 (symlink)! git ls-tree HEAD file.bin -# back to the adjusted branch: the content is there again -git switch "adjusted/master(unlocked)" +# back on the adjusted branch: content +git checkout "adjusted/master(unlocked)" cat file.bin # --- 03-filter @@ -50,14 +55,16 @@ cat file.bin git check-attr filter -- file.bin cat .git/info/attributes git config --get-regexp '^filter\.annex' -# post-checkout and post-merge run "git annex smudge --update" +# hooks run "git annex smudge --update" ls .git/hooks | grep -v sample -# git stores a pointer, git-annex put the content on disk +# 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 adjusting commit above +# 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 @@ -68,23 +75,27 @@ 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 copy of the junk commit, only the adjusting commit is gone +# 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: the path to data's object, master's symlink form +# still not data: master's path text cat data.bin -# master and basis still on the junk commit, the adjusted branch below them +# 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 top of master, junk included; "add precious data" is not in master ... +# 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 -# ... and "add precious data" is on no branch at all +# ... nor on any branch git log --all --oneline --no-decorate --grep "add precious data" -# precious.bin sits inside the adjusting commit instead, and so does data.bin's way back to 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 @@ -97,11 +108,14 @@ 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 -# the collaborator's commit on top of the junk, a new adjusting commit on top; no precious data anywhere +# 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 +# precious.bin is gone: the adjusted +# branch was rebuilt from basis ls -# and the junk is back: master never dropped it +# the junk is back: master never dropped it cat data.bin # --- 06-reset-pointer @@ -111,9 +125,10 @@ echo "edited" > notes.bin git reset --hard # git calls the work tree clean ... git status -# ... but the file holds the pointer, not the content: no hook ran after the reset +# ... but the file holds the pointer: +# no hook ran after the reset cat notes.bin -# post-checkout runs "git annex smudge --update" +# the post-checkout hook fills it in git checkout -- . # the content is back cat notes.bin @@ -126,7 +141,7 @@ 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 sits on top of them +# 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 -- 2.54.1 From 3f02337fe17a9f67c14d4d9490015a2eaed21ace Mon Sep 17 00:00:00 2001 From: Jiameng Wu Date: Tue, 17 Nov 2026 19:04:16 +0100 Subject: [PATCH 7/7] post: add answers to the puzzle The answers sit in a collapsed block, without explanations. Question 1 now names the work tree's checked-out branch and asks separately whether the sibling has each file's content, where the surprise lies. --- content/posts/adjusted-branch-unlocked/index.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/content/posts/adjusted-branch-unlocked/index.md b/content/posts/adjusted-branch-unlocked/index.md index 5b1e6b3..bfdef51 100644 --- a/content/posts/adjusted-branch-unlocked/index.md +++ b/content/posts/adjusted-branch-unlocked/index.md @@ -910,7 +910,7 @@ $ datalad push --to sibling {{< /dlcols >}} -1. Which of the two files, `saved-on-master.bin` and `saved-on-adjusted.bin`, are in your work tree, on the adjusted branch, on `master`, and on the sibling? +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`: @@ -934,6 +934,14 @@ $ datalad update --how=merge -s sibling 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. -- 2.54.1