The following steps are tested on Windows 10 21h1 with Ubuntu 20 and are designed to allow use of the annexed files through both WSL and Windows.

Limitations

  • The repository must be created with annex.tune.objecthashlower=true.
  • git annex adjust --unlock will not work. Unlocked files will work most of the time. Avoid annex.addunlocked=true because it is likely to not work.

Setup

  • Enable Developer mode in Windows settings so that symlinks can be created without elevated privileges.
  • Mount the NTFS drive with metadata option. /etc/wsl.conf can be used or a line such as C: /mnt/c drvfs metadata can be added in /etc/fstab.
  • Follow these steps in order when creating a new repository.
    • git config annex.sshcaching false
    • git annex init
    • git-annex should not detect the filesystem as crippled but now set git config annex.crippledfilesystem true
  • Safety of locked files will require these settings and scripts and the patch below.
    • git config annex.freezecontent-command 'wsl-freezecontent %path'
    • git config annex.thawcontent-command 'wsl-thawcontent %path'

wsl-freezecontent

#!/usr/bin/env bash

if [ -f "$1" ]; then
    if [[ "$1" == *.git/annex/objects/* ]]; then
        PERM='(DE,WD,AD)'
    else
        PERM='(WD,AD)'
    fi
elif [ -d "$1" ]; then
    PERM='(DE,DC,WD,AD)'
else
    exit 0
fi

OUTPUT="$(icacls.exe "$(wslpath -w "$1")" /deny "Authenticated Users:$PERM")"

if [ "$?" -ne 0 ]; then
    echo "$OUTPUT"
    exit 1
fi

wsl-thawcontent

#!/usr/bin/env bash

if [ -f "$1" ]; then
    PERM='(DE,WD,AD)'
elif [ -d "$1" ]; then
    PERM='(DE,DC,WD,AD)'
else
    exit 0
fi

OUTPUT="$(icacls.exe "$(wslpath -w "$1")" /grant "Authenticated Users:$PERM")"

if [ "$?" -ne 0 ]; then
    echo "$OUTPUT"
    exit 1
fi

Patches

This patch allows git annex fix on a crippled file system.

From 65fe6e362dfbf2f54c8da5ca17c59af26de5ff83 Mon Sep 17 00:00:00 2001
From: Reiko Asakura <asakurareiko@protonmail.ch>
Date: Sat, 23 Oct 2021 17:13:50 -0400
Subject: [PATCH 1/2] Allow git-annex fix on crippled filesystem

---
 Command/Fix.hs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Command/Fix.hs b/Command/Fix.hs
index 39853c894..2d66c1461 100644
--- a/Command/Fix.hs
+++ b/Command/Fix.hs
@@ -31,7 +31,7 @@ cmd = noCommit $ withAnnexOptions [annexedMatchingOptions] $
        paramPaths (withParams seek)

 seek :: CmdParams -> CommandSeek
-seek ps = unlessM crippledFileSystem $
+seek ps =
    withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
   where
    ww = WarnUnmatchLsFiles
-- 
2.30.2

Usage tips

  • WSL1 will not create symlinks that work in Windows if created before the target file exists, such as after git annex add or git annex get. This can be fixed by recreating them with any method, such as delete them and git checkout.

Sample script to recreate all symlinks under the current directory

#!/usr/bin/env python3

import pathlib
import os

def do(p):
    for c in list(p.iterdir()):
        if c.is_symlink() and c.resolve().exists():
            target = os.readlink(c) # use readlink here to get the relative link path
            c.unlink()
            c.symlink_to(target)
        elif c.is_dir() and c.name != '.git':
            do(c)

do(pathlib.Path('.'))

  • Sometimes there will SQLite errors using multiple jobs but retrying will work most of the time.

Related bugs

  • WSL adjusted braches: smudge fails with sqlite thread crashed - locking protocol
  • WSL1: git-annex-add fails in DrvFs filesystem
  • problems with SSH and relative paths