When using reinject <src> <dest>
and dest
is an absolute path to a
pointer file, the operation silently fails to reinject the content.
cd "$(mktemp -d "${TMPDIR:-/tmp}"/ga-XXXXXXX)" || exit 1
git version
git annex version | head -1
git init -q
git annex init
git config annex.addunlocked true
git annex fromkey --force \
SHA256E-s3--2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae \
foo
printf foo >.git/tmp-to-copy
git annex reinject .git/tmp-to-copy "$PWD"/foo
echo $?
cat foo
git version 2.31.1.705.g1ce651569c
git-annex version: 8.20210429-g06e996efa
init (scanning for unlocked files...)
ok
(recording state in git...)
fromkey foo ok
(recording state in git...)
0
/annex/objects/SHA256E-s3--2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
If a link destination is used (i.e. drop the addunlocked
configuration in the script above) or a relative path is used
(i.e. drop the "$PWD"/
), the content is injected.
It thinks the file is not annexed, due to asking git cat-file about it, and git cat-file not supporting paths that extend outside the repo.
Most commands pass through ls-files which makes absolute relative. A similar bug has been fixed earlier for --batch with absolute filenames, 957a87b437d6f056aa159e484a5f0a5af54e45db.
Also,
git-annex reinject /path/to/foo bar
fails to notice when the first parameter is an annexed file, for the same reason.And, grepping for ifAnnexed, whenAnnexed, and lookupKey, I found some other commands that also have the same problem, including rekey (also silently skips it), addurl --file (refuses to overwrite file, rather than adding url to key), rmurl (silently skips). Seems likely there are other commands with the bug too, that call those functions indirectly.
Also,
git annex reinject content ../thisrepo/foo
fails in a really ugly way with a lot of "is outside repository" from git (despite it being inside the repository).So I think that it probably makes sense for catKeyFile to fix up the path to avoid these problems. There could be other problems caused by absolute paths, but at least that would eliminate this particular set of bugs.
This also raises the question of why reinject silently ignores non-annexed files. I don't think there's really a good reason, other than git-annex generally ignoring non-annexed files. But in this case, the user is explicitly providing the content of the file, so has a high expectation it's annexed.